开发者

Android Parsing XML Problem with Character "<"

I am parsing a XML file and wrap it into a DOM object. But I encountered a problem while parsing the tags(of the XML file) with the following format:

<Teaser><p>String Content Here</p></Teaser>

I viewed the source code of the tag, it's:

<Teaser>&lt;p&gt;String C开发者_如何学Pythonontent Here&lt;/p&gt;</Teaser>

Here's my code:

NodeList teaserList = list.getElementsByTagName("Teaser");
teaserLen=teaserList.getLength();
String [] newsTeaser = new String[teaserLen];
for(int n2=0;n2<teaserLen;n2++){
newsTeaser[n2]=teaserList.item(n2).getFirstChild().getNodeValue();

 }

But I am only getting "<" for each tag. Because there is a pair <p></p> inside <Teaser></Teaser>, I wonder if android takes <p></p> as another tag, so I try:

newsTeaser[n2]=teaserList.item(n2).getChildNodes().item(0).getFirstChild().getNodeValue();

But I am getting an error. So android is not taking <p></p> as another tag. Does anyone know what to do?? I would like to get all the text insider <Teaser>, thus getting: <p>String Content Here</p>


Shouldn't it be :

newsTeaser[n2]=teaserList.item(n2).getChildNodes().item(1).getNodeValue();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜