简体   繁体   English

在标签之间读取XML数据

[英]Reading XML data between tags

I have a XML for which i am writing a servlet to pick up contents from the XML. 我有一个XML,我正在为其编写一个servlet来从XML中提取内容。 One such tag is <itunes:author>Jonathan Kendrick</itunes:author> 这样的标签之一就是<itunes:author>Jonathan Kendrick</itunes:author>
I need to get author value for this. 我需要为此获得作者价值。 because of : 由于

I tried using namespace and using escape sequence for : but it did not worked for me. 我尝试使用命名空间和使用转义序列但它并没有为我工作。

For rest of other XML elements i am simply using 对于其他XML元素,我只是使用

String link=node.getChildText("link").toString();

I am using Jdom parser 我正在使用Jdom解析器

in your XML the sequernce 'itunes:author' represents what's called a Q-Namem a "Qualified Name". 在您的XML中,序列'itunes:author'表示所谓的Q名称,即“合格名称”。 In XML it consists of a 'Namespace prefix', and a 'Local Name'. 在XML中,它由“名称空间前缀”和“本地名称”组成。 In your example, the namespace prefix is 'itunes', and the 'local name' is 'author'. 在您的示例中,名称空间前缀为“ itunes”,“本地名称”为“ author”。

What you want is the 'author' element in the namespace linked to the prefix 'itunes'. 您需要的是链接到前缀“ itunes”的名称空间中的“ author”元素。 The actual namespace is normally a full URL. 实际的名称空间通常是完整的URL。 I believe the full URL for your example is probably xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd", but you should check that. 我相信您的示例的完整URL可能是xmlns:itunes =“ http://www.itunes.com/dtds/podcast-1.0.dtd”,但是您应该检查一下。

So, the Namespace is "http://www.itunes.com/dtds/podcast-1.0.dtd", it's prefix is declared to be 'itunes' (but it could be something else - the actual prefix name is not technically important...) 因此,命名空间是“ http://www.itunes.com/dtds/podcast-1.0.dtd”,它的前缀被声明为“ itunes”(但可以是其他名称-实际的前缀名称在技术上并不重要) ...)

You want to get the 'author' in the 'http://www.itunes.com/dtds/podcast-1.0.dtd' Namespace so you want: 您想在“ http://www.itunes.com/dtds/podcast-1.0.dtd”命名空间中获得“作者”,因此您需要:

String author = node.getChildText("author", Namespace.getNamespace("http://www.itunes.com/dtds/podcast-1.0.dtd"));

For more information on Namespaces check out: http://www.w3schools.com/xml/xml_namespaces.asp 有关命名空间的更多信息,请访问: http : //www.w3schools.com/xml/xml_namespaces.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM