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><p>String C开发者_如何学Pythonontent Here</p></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();
精彩评论