OMElement.ToString()
返回<DPID>0d02</DPID>
但如何获得准确的值 0d02
?
String val = OMElement.GetText();
返回java.lang.NullPointerException
我不明白。
添加:
这是我的更多代码:
OMElement elem = null;
OMNode node = null;
String text;
Iterator children = getWSIDListByDPIDList.getChildren();
while(children.hasNext()){
node = null;
node = (OMNode)children.next();
if (node.getType() == OMNode.ELEMENT_NODE)
{
elem = (OMElement) node;
if (elem.getLocalName().equals("DPID"))
{
text = elem.getText();
}
}
最佳答案
根据OMElement documentation getText()
是正确的方法
这是一个简单的例子:
String xml = "<DPID>0d02</DPID>";
StringReader in = new StringReader(xml);
OMElement root = OMXMLBuilderFactory.createOMBuilder(in).getDocumentElement();
System.out.println(root.getText());
输出是:
0d02
也许您的代码中还有其他问题。
关于java - 如何获取OMElement值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36648892/