[英]SAXParseException code cvc-elt.1 for given xsd/ xml
I have a given xsd file and given examples for this file. 我有给定的xsd文件和该文件的示例。 the xsd is very similar to http://www.forum-datenaustausch.ch/hospitalinvoicerequest_400.xsd but with one additional element below the root.
xsd与http://www.forum-datenaustausch.ch/hospitalinvoicerequest_400.xsd非常相似,但根目录下有一个附加元素。
The problem is if i validate the given xml against the schema (using moxy as JAXBCOntextFactory) i got this error: 问题是如果我针对架构验证给定的xml(使用moxy作为JAXBCOntextFactory),则会收到此错误:
enterCaused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 221; cvc-elt.1: Cannot find the declaration of element 'invoice:request'.
invoice:request is the root element the xml begins: invoice:request是xml开始的根元素:
<invoice:request role="production" xmlns:invoice="http://www.medidata.ch/QO/XSD" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.medidata.ch/QO/XSD QO_MDInvoiceRequest_400.xsd">
If i validate the xml against the schema online or in eclipse (right click validate) all works fine. 如果我在线或在Eclipse(右键单击验证)中针对架构验证xml,则一切正常。 And if i change the name space from
如果我将名称空间从
xmlns:invoice="http://www.medidata.ch/QO/XSD"
to 至
xmlns:invoice="http://www.xmlData.ch/xmlInvoice/XSD"
the error disappears - but i get another one because of the additional element. 错误消失了-但是由于其他因素,我得到了另一个错误。 With this name space declaration i can't even read the contents without validation: the getter for root returns null.
使用这个名称空间声明,我什至无法在没有验证的情况下读取内容:root的getter返回null。 With the alternative declaration (" http://www.xmlData.ch/xmlInvoice/XSD ") and without validation all works fine!
使用替代声明(“ http://www.xmlData.ch/xmlInvoice/XSD ”)并且无需验证,一切正常!
So whats wrong with the name space declaration? 那么名称空间声明怎么了?
The error says that your document is not valid because there is no definition for an element with local name request
and namespace prefix invoice
. 该错误表明您的文档无效,因为没有定义具有本地名称
request
和名称空间前缀invoice
的元素。 Your instance document has a namespace binding for that prefix and schema location hint for the same namespace URI, so that part seems to be correct. 您的实例文档具有用于该前缀的名称空间绑定和同一名称空间URI的架构位置提示,因此该部分似乎是正确的。
Check your schema for the following problems: 检查您的架构是否存在以下问题:
http://www.medidata.ch/QO/XSD
) http://www.medidata.ch/QO/XSD
) request
) request
) If any of these is incorrect, your document is invalid. 如果其中任何一个不正确,则您的文档无效。 (There might also be other problems later on in your schema or in the instance XML document that makes it invalid.)
(稍后,在您的架构或实例XML文档中可能还会出现其他问题,导致其无效。)
Usually (if your XML document really is valid) such problem is caused by either one of these two reasons: 通常(如果您的XML文档确实有效),则此问题是由以下两个原因之一引起的:
The markup xsi:schemaLocation="http://www.medidata.ch/QO/XSD QO_MDInvoiceRequest_400.xsd"
defines that the schema for elements in namespace http://www.medidata.ch/QO/XSD
is found from the relative (file) location QO_MDInvoiceRequest_400.xsd
. 标记
xsi:schemaLocation="http://www.medidata.ch/QO/XSD QO_MDInvoiceRequest_400.xsd"
定义了从相对地址中找到名称空间http://www.medidata.ch/QO/XSD
元素的架构(文件)位置QO_MDInvoiceRequest_400.xsd
。 So if you don't specifically tell the parser what schema document it should use, it will look for a file with that name from the same folder where the input document is. 因此,如果您没有明确告诉解析器应该使用哪个架构文档,它将从输入文档所在的文件夹中查找具有该名称的文件。
For the second reason I can't give any good help since I'm not familiar with moxy but/and I am in the assumption that moxy always handles XML files as namespace aware. 出于第二个原因,由于我不熟悉moxy,但是我//我假设moxy始终将XML文件作为名称空间感知来处理,因此我无法提供任何帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.