【问题标题】:problems with xml schema referencexml架构参考的问题
【发布时间】:2016-04-19 14:21:25
【问题描述】:

我的 xml 架构和我的 xml 文档都是有效且格式正确的。但是正确的参考还是有问题的。我查了几个类似的问题,但我无法解决我的问题。

xml 架构的开始:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com">


<xs:element name="catalog"/>

xml 架构示例:

<xs:element name="Qstr">
<xs:complexType>
    <xs:sequence>
        <xs:element name="text" type="xs:string"/>
        <xs:element name="a" type="xs:string"/>
        <xs:element name="b" type="xs:string"/>
        <xs:element name="c" type="xs:string"/>
        <xs:element name="d" type="xs:string"/>
    </xs:sequence>
</xs:complexType>

xml 文档的开头:

<?xml version="1.0" encoding="UTF-8"?>



<catalog xmlns="http://www.w3schools.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3schools.com   file:///home/n/workspace/webprog1/WebContent/schema.xml">

<Qstr>
    <text>random question?</text>
    <a>asdfasd</a>
    <b>ertwetrewt</b>
    <c>ghkghk</c>
    <d>xcvbxcbbx</d>
</Qstr>

错误信息:

 Invalid content was found starting with element '{"http://www.w3schools.com":text}'. One of '{text}' is expected.

【问题讨论】:

  • 显示架构中讨论“文本”的部分。

标签: xml


【解决方案1】:

elementFormDefault 的默认值为 unqualified。因为您使用的是带有&lt;catalog&gt; 的默认命名空间,所以所有子元素也将采用相同的命名空间,而不是没有命名空间(这是您想要的)。

例如请参阅here 了解更多信息。

如果您更改为以下内容,它可能会(您没有粘贴完整的 XSD)工作:

<myns:catalog xmlns:myns="http://www.w3schools.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3schools.com   file:///home/n/workspace/webprog1/WebContent/schema.xml">

<myns:Qstr>
    <text>random question?</text>
    <a>asdfasd</a>
    <b>ertwetrewt</b>
    <c>ghkghk</c>
    <d>xcvbxcbbx</d>
</myns:Qstr>

【讨论】:

  • 感谢您的回复,我将 elementFormDefault 设置为“合格”,现在我m getting no errors. My actual problem(transforming the xml file to html) isnt 已解决,但我已经在另一个问题中询问过。
  • 好的,如果有帮助,请接受或至少投票赞成答案。谢谢。
猜你喜欢
  • 1970-01-01
  • 2015-01-13
  • 2014-08-24
  • 1970-01-01
  • 2016-03-31
  • 1970-01-01
  • 1970-01-01
  • 2011-07-18
  • 1970-01-01
相关资源
最近更新 更多