【发布时间】:2012-03-15 13:02:12
【问题描述】:
我正在测试如何使用SAXParser 并了解它的组件。这是我用来测试的 XML 文件:
<?xml-stylesheet href="/externalflash/NASA_Detail/NASA_Detail.xsl" type="text/xsl"?>
<rss version="2.0">
<channel>
<title>NASA Image of the Day</title>
<link>http://www.nasa.gov/multimedia/imagegallery/index.html</link>
<description>The latest NASA "Image of the Day" image.</description>
<language>en-us</language>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<managingEditor>yvette.smith-1@nasa.gov</managingEditor>
<webMaster>brian.dunbar@nasa.gov</webMaster>
<item xmlns:java_code="xalan://gov.nasa.build.Utils1">
<title>Expedition 30 Cosmonauts Perform Spacewalk</title>
<link>http://www.nasa.gov/multimedia/imagegallery/image_feature_2181.html</link>
<description>This image of Russian cosmonauts Oleg Kononenko and Anton Shkaplerov, both Expedition 30 flight engineers, was taken during a spacewalk on Thursday, Feb. 16, 2012. During the six-hour, 15-minute spacewalk, Kononenko and Shkaplerov moved the Strela-1 crane from the Pirs Docking Compartment in preparation for replacing it in 2012 with a new laboratory and docking module. The duo used another boom, the Strela-2, to move the hand-operated crane to the Poisk module for future assembly and maintenance work. Both telescoping booms extend like fishing rods and are used to move massive components outside the station. On the exterior of the Poisk Mini-Research Module 2, they also installed the Vinoslivost Materials Sample Experiment, which will investigate the influence of space on the mechanical properties of the materials. The spacewalkers also collected a test sample from underneath the insulation on the Zvezda Service Module to search for any signs of living organisms. Both spacewalkers wore Russian Orlan spacesuits bearing blue stripes and equipped with NASA helmet cameras. Image Credit: NASA</description>
<guid isPermaLink="true">http://www.nasa.gov/multimedia/imagegallery/image_feature_2181.html</guid>
<pubDate>Wed, 22 Feb 2012 00:00:00 EST</pubDate>
<enclosure length="1234567" type="image/jpeg" url="http://www.nasa.gov/images/content/624856main_image_2181_516-387.jpg"/>
</item>
</channel>
</rss>
当我使用 SAXParser 测试这个文件时,这里是我的一些输出:
start Element: rss
Local Name // this line I don't know why null
qNam: rss
start characters:
start Element: channel
Local Name
qNam: channel
start characters:
我的问题是:在我的 XML 文件中,没有namespace,所以每个元素都属于其默认的namespace,这就是为什么qName 将等于local Name(因为qName 没有prefix) .
但在上述结果中,在元素 rss 和 channel(以及我尚未发布的所有其他元素)处,local Name 为空!!!
谁能帮我解释一下。
谢谢:)
【问题讨论】:
-
它不是“null”,它是空白的。重要区别。
标签: java xml namespaces sax