我有XML文件的此示例:XML解析读取XML标签作为文本内容
<Cells>
<Cell row="1" column="1">p</Cell>
<Cells>
哪里是p是单元格的内容..但有时我需要把内容的XML标签内,我想阅读他们作为简单的文字,而不是XML标签...类似的东西:
<Cells>
<Cell row="1" column="1">p</Cell>
<Cell row="2" column="2"><Cell></Cell>
<Cell row="3" column="3"></Cell></Cell>
<Cells>
我该怎么办?要阅读此XML我使用类似的东西:
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("Cell");
cell = new String[nList.getLength()][4];
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
cell[temp][1] = eElement.getAttribute("row");
cell[temp][2] = eElement.getAttribute("column");
cell[temp][3] = eElement.getTextContent();
}
}
因此,有什么办法可以阅读<细胞>或< /细胞>一个<细胞内> .... < /电池>作为内容和不是xml标签?
谢谢!
您可以使用'CDATA'。 –
但我不能改变XML ...我觉得CDATA只适用于如果我直接在xml上写cdata,我错了吗? – Joseph
是的,当然,您必须使用CDATA以XML格式编写标签。否则,它将不会是格式良好的XML。 –