通过一个java程序,我正在创建一个股东的xml。生成的 xml 看起来像 -
<?xml version="1.0" encoding="UTF-8" ?>
<urlset>
<url>
<loc>FirstName-LastName/id/</loc>
</url>
</urlset>
有些股东的名字中有特殊字符,例如 A. Pitkänen。现在,当我看到这个股票持有人的 xml 时,它看起来像 -
<?xml version="1.0" encoding="UTF-8" ?>
<urlset>
<url>
<loc>/A-Pitk寥n/ELS_1005091/</loc>
</url>
</urlset>
这使 xml 无效。为什么会这样?java程序是-
FileWriter fstream = new FileWriter("c:\stock-holders.xml");
final BufferedWriter out = new BufferedWriter(fstream);
try {
// Making Connection and query the stock holders to get the resultset
String aId = "";
String aFName = "";
String aLName = "";
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
out.write("<urlset>\n");
while (rs.next()) {
String url = "";
aFName = rs.getString(2);
if (StringUtils.isNotEmpty(aFName) ) {
aFName = aFName.trim();
url += aFName;
}
aLName = rs.getString(3);
if (StringUtils.isNotEmpty(aLName)) {
aLName = aLName.trim();
url += "-" + aFName;
}
aId = rs.getString(1);
if (StringUtils.isNotEmpty(aId)) {
aId = aId.trim();
url += "/" + aId + "/";
}
out.write("<url>\n");
out.write("<loc>" + url + "</loc>\n");
out.write("</url>\n");
out.flush();
}
out.write("</urlset>");
out.close();
}