我正在寻找一种方法来解析文本中的元素。
例如我有以下xml
<Elem1>
<Elem1.1>{some text} <newLine/> {some text}</Elem1.1>
</Elem1>
所以我可以访问 Elem1.1 元素,但是当我在节点上调用 .getTextContent() 时,我会从它返回 {some text}{some text} (所以标签基本上已被删除)。
如何获得该新行,以便我可以用我从这个 xml 解析的 json 对象中的 \n 替换它?
这基本上就是我现在所拥有的
NodeList nodeList = document.getElementsByTagName("Elem1");
for(int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
NodeList nodeList2 = ((Element)node).getElementsNyTagName("Elem1.1");
for(int j = 0; j < nodeList2.getLength(); j++) {
Element elem11 = (Element)nodeList2.item(j);
// Add elem11.getTextContent() to an object and later use GSON to convert to Json string and save to file
}
}
谢谢, 曼