简体   繁体   English

给定xsd / xml的SAXParseException代码cvc-elt.1

[英]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: 检查您的架构是否存在以下问题:

  1. Is the target namespace of the schema the same as the one used by the root element of your document (here http://www.medidata.ch/QO/XSD ) 模式的目标名称空间是否与文档的根元素所使用的名称空间相同(此处为http://www.medidata.ch/QO/XSD
  2. Is there a global element declaration for an element with the same local name as your root element (here request ) 是否存在与本地元素具有相同本地名称的全局元素声明(此处为request
  3. If the your root element is declared in the schema with a namespace prefix, is that prefix bound to same namespace URI that is used in your document 如果您的根元素是在模式中使用名称空间前缀声明的,则该前缀是否绑定到文档中使用的相同名称空间URI

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文档确实有效),则此问题是由以下两个原因之一引起的:

  1. your schema document is not found 找不到您的架构文件
  2. the element name is misinterpreted because the parser is not set to be namespace aware 元素名称被误解,因为解析器未设置为可识别名称空间

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.

相关问题 XML,XSD,cvc-elt.1:找不到元素的声明 - XML, XSD, cvc-elt.1: Cannot find the declaration of element XML解析异常org.xml.sax.SAXParseException cvc-elt.1 - XML parsing exception org.xml.sax.SAXParseException cvc-elt.1 org.xml.sax.SAXParseException; lineNumber:6; columnNumber:122; cvc-elt.1:找不到元素&#39;beans&#39;的声明 - org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 122; cvc-elt.1: Cannot find the declaration of element 'beans' JAXB解组架构问题:“ org.xml.sax.SAXParseException cvc-elt.1” - JAXB unmarshalling schema issues: 'org.xml.sax.SAXParseException cvc-elt.1' org.xml.sax.SAXParseException:cvc-elt.1:找不到元素'tns:root_element'的声明 - org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'tns:root_element' SAXParseException:cvc-elt.1:找不到元素&#39;Document&#39;的声明 - SAXParseException: cvc-elt.1: Cannot find the declaration of element 'Document' cvc-elt.1:找不到元素&#39;staff&#39;的声明-无法针对xsd验证xml - cvc-elt.1: Cannot find the declaration of element 'staff' - Cannot validate xml against a xsd 针对XSD的XML验证:cvc-elt.1:找不到元素&#39;xxx&#39;的声明 - XML validation against XSD: cvc-elt.1: Cannot find the declaration of element 'xxx' 无法针对xsd验证xml。 错误“ cvc-elt.1:找不到元素&#39;systems&#39;的声明” - Cannot validate xml against a xsd. Error “cvc-elt.1: Cannot find the declaration of element 'systems'” root-context.xml] 无效; 嵌套异常是 org.xml.sax.SAXParseException; cvc-elt.1: 找不到元素 'beans' 的声明 - root-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; cvc-elt.1: Cannot find the declaration of element 'beans'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM