亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在java中將xml解析為字符串以在sitemap.xml中給出優先級值

在java中將xml解析為字符串以在sitemap.xml中給出優先級值

肥皂起泡泡 2023-11-01 16:33:57
在我的網站根目錄中,java servlet 已準備好 content/falcon/en/index 后的所有文件并創建 sitemap.xml  <url><loc>https://www.ded.com/</loc><lastmod>2019-08-29</lastmod><changefreq>weekly</changefreq><priority>0.9</priority></url><url><loc>https://www.ded.com/eFNOL/eFNOL_Login?SO=01</loc><lastmod>2019-08-29</lastmod><changefreq>weekly</changefreq><priority>0.9</priority></url><url><loc>https://www.ded.com/customerselfservice/CSSU</loc><lastmod>2019-08-29</lastmod><changefreq>weekly</changefreq><priority>0.9</priority></url><url><loc>https://www.dede.com/claims/roadside-assistance/</loc><lastmod>2019-08-29</lastmod><changefreq>weekly</changefreq><priority>0.9</priority></url><url><loc>https://www.dede.com/payments/</loc><lastmod>2019-08-29</lastmod><changefreq>weekly</changefreq><priority>0.9</priority></url><url><loc>https://www.ded.com/insurance/</loc><lastmod>2019-08-29</lastmod><changefreq>weekly</changefreq><priority>0.9</priority></url><url><loc>https://www.dede.com/home/</loc><lastmod>2019-08-29</lastmod><changefreq>weekly</changefreq><priority>0.9</priority></url>
查看完整描述

1 回答

?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

您可以添加以下方法來設置優先級:


public static String getPriority (String location){

    switch(countSlashes(location)){

        case 3: return "1";

        case 4: return "0.9";

        case 5: return "0.8";

        case 6: return "0.7";

        default: return "0.0"; //or whatever prio in default case

    }

}


//replace everything except '/' to get count of slashes easily

private static int countSlashes(String location) {

    return location.replaceAll("[^/]", "").length();

}

然后您可以getPriority從您的createXMLNode方法中調用,如下所示:


.....


String location = request.getScheme() + "://" + request.getServerName() + childPage.getPath();

locElementNode.setTextContent(location);

....


priorityElementNode.setTextContent(getPriority(location));


....


查看完整回答
反對 回復 2023-11-01
  • 1 回答
  • 0 關注
  • 179 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號