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));
....
添加回答
举报