English 中文(简体)
具有“<<>”特征的苯胺醇/六氯环己烷问题
原标题:Android Parsing XML Problem with Character "<"

我将XML文件编成一个DOM物体。 但是,我遇到了一个问题,把 X(XML案卷)与以下格式混为一谈:

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

我对标签的源代码进行了观察。

<Teaser>&lt;p&gt;String Content Here&lt;/p&gt;</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();

 }

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>

最佳回答

如果是:

newsTeaser[n2]=teaserList.item(n2).getChildNodes().item(1).getNodeValue();
问题回答

暂无回答




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签