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"));

私はアンドロイドクエリを使用していますが、これで問題なくフォーマットできます:

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));
        }

entry タグを変数に追加し、string replace を使用して cdata を取り除き、タグ内のすべてのテキストを表示します。正常に動作します。

于 2013-08-20T23:24:00.980 に答える