Java 在Android中使用Dom从XML树获取HTML内容
我有这样一个Xml:Java 在Android中使用Dom从XML树获取HTML内容,java,android,xml,dom,Java,Android,Xml,Dom,我有这样一个Xml: <root> <item> <content type="HTML"> <![CDATA[<html> <head></head> <body>something goes there</body> </html>]]> </content>
<root>
<item>
<content type="HTML">
<![CDATA[<html>
<head></head>
<body>something goes there</body>
</html>]]>
</content>
</item>
<item>
<content type="Text">
Something goes there
</content>
</item>
</root>
如果内容是文本类型,我可以使用node.getTextContent获取。问题是我想从Xml树获取所有Html内容。所以我想要得到的结果是字符串:
"<html><head></head><body>some thing goes there</body></html>"
在Android中如何使用文档DOM实现这一点?
注意:因为我必须编辑一些xml内容,所以我不能使用SAX。请参见DOM解析器示例: xml可能具有不同类型的节点,请参见可能的节点类型: android中有各种方法可以通过DOM解析器解析Xml,有用的方法如下:
getElementsByTagName - Return Array of Nodes by Tag Name specified.
getChildNodes - retervies the list of childs of Node
getAttributes()- retrieves attributes of a Node
getFirstChild- returns first child node of Node Object
getNodeName, getNodeType, getNodeValue- returns corresponding values from Node
谢谢我已经阅读了这些API。但要解决我的问题并不容易,因为我不仅需要节点名和值,还需要标记。那么,问题是如何?