我使用org.w3c.dom.Node
的getNodeValue()
来获取XML标记值。如果一个值包含ä,ö,ü或其他特殊字符,我的程序只会切断字符串;例如“Türen”将变成“T”。我怎样才能得到完整的价值,特殊的字符?为什么不能从org.w3c.dom解析ü,ö,ä,&c。中的getNodeValue()?
我打电话getTextValueOfFirstChild得到textvalue
public static String getTextValueOfFirstChild(Node node, String childName)
{
Node node1;
Node node2;
if((node1 = getFirstChildNode(node, childName)) != null && (node2 = node1.getFirstChild()) != null)
return node2.getNodeValue();
else
return null;
}
public static Node getFirstChildNode(Node parent, String name)
{
if(parent != null)
{
NodeList nodelist;
int i = (nodelist = parent.getChildNodes()).getLength();
for(int j = 0; j < i; j++)
{
Node node = nodelist.item(j);
if(name.equals(node.getNodeName()))
return node;
}
}
return null;
}
<carinfo>
<id>l3nqd2dpwikl</id>
<makename>Fiat</makename>
<modelname>Ducato</modelname>
<typename>HKAWA 30 L2H2 120 Multijet</typename>
<bodytype>2/3 Türen</bodytype>
<extrainfo/>
<bodycolorid/>
<intcolorid>0</intcolorid>
<logo/>
问题可能出在您解析XML以创建DOM的方式。我希望你没有使用正确的字符集。请显示代码...和XML文件的前几行。 – 2011-04-05 14:21:43
请重新阅读我的评论。您没有提供我要求的代码*。 – 2011-04-07 02:25:06