0

我正在尝试从如下所示的 xml 文件中获取文本:

<description>
<p>
<strong>Last updated:</strong>
 Mon, 19 Aug 2013 23:52:31</p>
<p>Incident is 53% contained.</p>
<![CDATA[<p>The American Fire burning in heavy fuels on extreme slopes about 10 air miles northeast of the community of Foresthill, California, and eight air miles south of Interstate 80 has grown to 14,765 acres.</p> <p><strong>The public is invited to an American Fire update meeting at the Foresthill Veteran's Memorial Hall at 24601 Harrison Street in Foresthill beginning at 7 p.m. tonight.</strong></p> <p>Heavy smoke shaded the fire yesterday, moderating fire behavior. Backing fire with single and group tree torching was observed. On the northeast corner a spot fire was quickly contained by firefighters as they made good progress with hand lines and dozer lines. Along the eastern portion of the fire last night, firefighters conducted a firing operation, meaning they used fire to reduce unburned fuel between the fire line and the main fire. The center portion of the east flank was still very active during the day, but indirect containment lines remained secure. On the extreme south end, firefighters will begin building a very steep hand line today, which descends to the river. The west side of the fire was relatively inactive. Mop-up is occurring in this area, which involves checking the interior of the fire to ensure no hot spots remain that may threaten the containment lines.</p> <p>Firefighters continue to be concerned about dry fuels that have not seen fire in over a century, as well as any winds over 5 m.p.h. and rolling burning debris, all of which could cause a rapid spread of the fire.</p> <p>The National Weather Service has issued a Red Flag Warning for the fire area beginning at 11 a.m. today and extending through 11 p.m. Wednesday. This Warning is due to the threat of abundant lightning and gusty, erratic outflow winds. Significant rainfall and flooding in and around the fire is also possible over the next three days.</p> <p>The Robinson Flat Campground is closed. The Tahoe National Forest has issued a voluntary evacuation notice for Big Oak Flat located near the south end of the fire. Forest Road 43 (Robinson Flat Road) is closed at its intersection with Forest Road 96 (Mosquito Ridge Road).</p> <p>An emergency closure order is in place for portions of National Forest System lands within and adjacent to the American Fire. A map and description of the closed area can be obtained at Tahoe National Forest offices as well as online at <a href="http://www.fs.usda.gov/tahoe">http://www.fs.usda.gov/tahoe</a>. Portions of the Foresthill Divide road are closed.</p> <p><strong>At 6 a.m. today, management of the fire was transferred to the California Interagency Management Team 4.</strong></p> <p>Firefighter and public safety are the highest priority.</p>]]>
<p>
<a href="http://inciweb.nwcg.gov/incident/3624/">View American Wildfire web site</a>
</p>
<p>
<strong>NOTE: </strong>
 All fire perimeters and points are approximations.</p>
</description>

当我解析它时,我可以获得 CDATA 区域内的所有信息,但其余部分被忽略。我正在解析并放入我的文本视图中,如下所示:

description.setText(extras.getString("desc"));

我正在使用android查询并且可以让它格式化没有问题:

aq.id(R.id.description).text(Html.fromHtml(extras.getString("desc")));

但是,同样的问题,只是获取 cdata 信息。我的 log.v() 只显示 cdata 之间的信息。所以我想我需要以某种方式逃避它?为什么 cdata 之外的文本被忽略?

谢谢,谢谢

4

2 回答 2

2

只是改变

if(child.getNodeType() == Node.TEXT_NODE)

if (child.getNodeType()  == Node.CDATA_SECTION_NODE || child.getNodeType() == Node.TEXT_NODE)

在 XMLParser.java 文件中。

于 2013-11-27T12:44:28.600 回答
0

我能够以这种方式摆脱 cdata :

for (XmlDom entry : entries) {
            XmlDom description = entry.tag("description");
            String cdatareplace = description.toString();
            String desc = cdatareplace.replace("<![CDATA[", "");
            desc = desc.replace("]]>", "");
            kmllist.add(new KML(entry.text("name"), desc));
        }

将入口标签添加到变量中,然后使用字符串替换来删除 cdata,然后显示标签内的所有文本。工作正常。

于 2013-08-20T23:24:00.980 回答