我正在解析一个 XML 文件并将其包装到一个 DOM 对象中。但是我在用以下格式解析(XML文件的)标签时遇到了问题:
<Teaser><p>String Content Here</p></Teaser>
我查看了标签的源代码,它是:
<Teaser><p>String Content Here</p></Teaser>
这是我的代码:
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();
}
但我只得到“<”对于每个标签。
因为
里面有一对
,所以我想知道android是否接受
作为另一个标签,所以我尝试:
newsTeaser[n2]=teaserList.item(n2).getChildNodes().item(0).getFirstChild().getNodeValue();
但我收到错误。所以 android 不会将
作为另一个标签。
有谁知道该怎么办吗??我想获取
内部的所有文本,从而获得:
String Content Here
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 Content 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 :