Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 允许来自具有两个模式的特定命名空间的任何元素 编辑:前言:_Xml_Xsd_Xml Validation_Xsd Validation - Fatal编程技术网

Xml 允许来自具有两个模式的特定命名空间的任何元素 编辑:前言:

Xml 允许来自具有两个模式的特定命名空间的任何元素 编辑:前言:,xml,xsd,xml-validation,xsd-validation,Xml,Xsd,Xml Validation,Xsd Validation,下面是标题中描述的问题的一个特定实例。我有一个由两个文档共享的名称空间;一个进口另一个。然而,导入似乎混淆了元素“any”上的namespace属性 目标是: 对xml进行验证;“any”元素应该只检查目标命名空间中的元素。也就是说,只有元素“东西”或“产品”(及其子元素)应该验证 错误: 匹配的通配符是严格的,但找不到任何声明 对于元素'stuff'。” 我要严格匹配 模式1: 模式2: XML: 小装置 文本 编辑:想法: 基于错误,xml似乎找不到声明“stuff”的模式,

下面是标题中描述的问题的一个特定实例。我有一个由两个文档共享的名称空间;一个进口另一个。然而,导入似乎混淆了元素“any”上的namespace属性

目标是: 对xml进行验证;“any”元素应该只检查目标命名空间中的元素。也就是说,只有元素“东西”或“产品”(及其子元素)应该验证

错误: 匹配的通配符是严格的,但找不到任何声明 对于元素'stuff'。” 我要严格匹配

模式1:

模式2:

XML:

小装置
文本
编辑:想法: 基于错误,xml似乎找不到声明“stuff”的模式,即targetNamespace“!我不知道为什么会出现这种情况。非常感谢您的帮助,因为这个问题已经困扰了我两天了

编辑2:解决方案: 模式1():


模式2():


到目前为止,这个解决方案对我来说非常有效。元素“anynamespace=“##targetNamespace”/将查找包含在中心文件(包括文件)中的每个元素。美妙之处在于,通过这种设置,名称空间是同质的,因此我可以忽略xml和xsd文件中的前缀,同时包括任意数量的支持模式,但我只需要一个文件来验证


欢迎反馈:D

看,您遇到了以下错误:

匹配的通配符是严格的,但找不到元素“stuff”的声明

注意,它没有提到元素的名称空间。 相反,它只是找不到元素
stuff
的声明

然而,从表面上看,您似乎确实声明了该元素:

<xsd:element name="Company">
  <xsd:complexType>
    <xsd:sequence>
       <xsd:element name="Product" type="ProductType"
                    maxOccurs="unbounded"/>

       <xsd:element name="stuff" type="xsd:string" />
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>
当它在
中找到
时,它会查找路径:

Company/Product/stuff
这是未知的。然后,它只是说它找不到
的声明。它不会进一步分析你可能做错了什么

因此,问题实际上不是关于名称空间,而是关于本地声明的元素。
你应该重新设计你的模式来修复它

模式重新设计有帮助,我实际上将元素声明从移动到了导入的模式。然后我在company.org上加了一个“any”。我将很快用解决方案更新我的帖子。谢谢
<?xml version="1.0"?>
<Company xmlns="http://www.company.org"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.company.org /u/name/test/file1.xsd"
>

    <Product>
            <stuff>Widget</stuff>
    </Product>
    <stuff>text</stuff>
</Company>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.company.org"
        xmlns="http://www.company.org"
        elementFormDefault="qualified">

    <xsd:include schemaLocation="http://www.product.org"/>

    <xsd:element name="Company">
        <xsd:complexType>
            <xsd:choice minOccurs="0" maxOccurs="unbounded" >
                <xsd:any namespace="##targetNamespace"  />
            </xsd:choice>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>
<xsd:schema 
    xmlns="http://www.company.org" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.company.org" 
    elementFormDefault="qualified"
    >

    <xsd:simpleType name="stuff">
        <xsd:restriction base="xsd:string" />
    </xsd:simpleType>

    <xsd:complexType name="ProductType">
        <xsd:sequence>
            <xsd:any minOccurs="1" maxOccurs="unbounded" 
            namespace="http://www.company.org" processContents="strict" />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="Product" type="ProductType" />
    <xsd:element name="stuff" type="stuff" />

</xsd:schema>
<xsd:element name="Company">
  <xsd:complexType>
    <xsd:sequence>
       <xsd:element name="Product" type="ProductType"
                    maxOccurs="unbounded"/>

       <xsd:element name="stuff" type="xsd:string" />
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>
<Product>
        <stuff>Widget</stuff>
</Product>
<stuff>text</stuff>
Company/stuff
Company/Product/stuff