我创建了一个由解析器解析的XML文件。这是与this类似的RSS atom文件。它是第三方java解析器,我不知道其他细节。
XML文件是
<?xml version = '1.0' encoding = 'UTF-8' standalone = 'yes'?>
<?xml-stylesheet href='http://alerts.weather.gov/cap/capatom.xsl' type='text/xsl'?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:cap="urn:oasis:names:tc:emergency:cap:1.2">
<title type="text">Feeds Test</title>
<subtitle type="text">Contains feeds generated by Me</subtitle>
<id>uuid:1f48fcf1-cf2d-40bf-896f-e0f318e0fa52;id=1</id>
<updated>2015-03-23T10:26:04Z</updated>
<generator>MNS</generator>
<link rel="self" type="text/html" title="TestRave Feeds" href="http://111.111.111.111//TestRave_atom_en_US.xml" />
<entry>
<id>6e21968e-ec73-46c8-bcf3-7bfb295ff59b</id>
<title type="text">LAUNCHED : 3/23/2015 10:26:03 AM: Title for CAP notification message in English</title>
<published>2015-03-23T10:26:03+05:30</published>
<updated>2015-03-23T10:26:03+05:30</updated>
<author>
<email>myname@domain.com</email>
</author>
<link rel="alternate" href="http://111.111.111.111//feed_6e21968e-ec73-46c8-bcf3-7bfb295ff59b_en_US.cap" />
<content type="text">LAUNCHED : 3/23/2015 10:26:03 AM: Short Text for CAP message</content>
<cap:records>3ae449ba-ec23-4c8d-9ea6-51d0078fd046</cap:records>
</entry>
</feed>
在解析时,解析器在处理XML时会抛出跟随错误。
XML验证错误:cvc-elt.1.a:找不到声明 元素&#39; feed&#39;。
关于这个问题的任何想法?
答案 0 :(得分:0)
在您的情况下,该错误消息告诉您解析器无法在feed
命名空间中找到定义http://www.w3.org/2005/Atom
的XSD。将XSD与文档实例相关联的一种方法是通过xsi:schemaLocation
:
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:cap="urn:oasis:names:tc:emergency:cap:1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2005/Atom
http://exyus.com/xcs/tasklist/source/?f=put_atom.xsd">
请注意xsi:schemaLocation
采用命名空间位置对。我冒昧地找到了适用于你的Atom XSD。您可能想要同一个不同的位置或不同的位置。
您会发现您的下一个错误是由于您没有将urn:oasis:names:tc:emergency:cap:1.2
与XSD相关联而导致的。您可以类似地解决该问题。
答案 1 :(得分:0)
关闭它,因为它是文本的格式。在某些地方,格式是BOM而不是UTF