简体   繁体   English

XML / XSD-如何在其自身中递归引用complexType?

[英]XML / XSD - How do I reference a complexType within Itself recursively?

My question is very similar to What xsd will let an element have itself as a sub element infinitely? 我的问题非常类似于xsd将让元素无限地将自身作为子元素吗? .

What I want to do is utilize an XML structure that is able to create a Skeleton within XML. 我想做的是利用一种XML结构,该结构能够在XML内创建Skeleton。 The XML will have a top level complexType that includes a recursive list of Bone complexTypes that include their own attributes and element data. XML将具有顶级complexType,其中包括Bone complexType的递归列表,其中包括它们自己的属性和元素数据。

The XML I am using is here: 我正在使用的XML在这里:

<SkeletalMapping xmlns="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test SkeletalDefinition.xsd">

<Skeleton sourceSkeleton="Max" targetSkeleton="UDK" version="1.0">
    <Bone name="Origin" target="ROOT">
        <PivotPoint x="0.0" y="0.0" z="0.0" />
        <Bone name="UpperBody" target="SPINE">
            <PivotPoint x="0.0" y="0.033" z="0.438" />
            <Bone name="Head" target="HEAD">
                <PivotPoint x="0.0" y="0.006" z="0.667" />
            </Bone>
            <Bone name="RightArm" target="RIGHT_ARM">
                <PivotPoint x="-0.203" y="0.05" z="0.477" />
                <Bone name="LRightHand" target="RIGHT_HAND">
                    <PivotPoint x="-0.586" y="0.074" z="0.067" />
                </Bone> <!-- LeftHand -->
            </Bone> <!-- LeftArm -->
            <Bone name="LeftArm" target="LEFT_ARM">
                <PivotPoint x="0.203" y="0.05" z="0.477" />
                <Bone name="LeftHand" target="LEFT_HAND">
                    <PivotPoint x="0.587" y="0.074" z="0.066" />
                </Bone> <!-- LeftHand -->
            </Bone> <!-- LeftArm -->
        </Bone> <!-- UpperBody -->
        <Bone name="RightLeg" target="RIGHT_LEG">
            <PivotPoint x="-0.14" y="-0.019" z="-0.467" />
            <Bone name="RightFoot" target="RIGHT_FOOT">
                <PivotPoint x="-0.17" y="0.083" z="-0.889" />
            </Bone> <!-- RightFoot -->
        </Bone> <!-- RightLeg -->
        <Bone name="LeftLeg" target="LEFT_LEG">
            <PivotPoint x="0.14" y="-0.019" z="-0.467" />
            <Bone name="LeftFoot" target="LEFT_FOOT">
                <PivotPoint x="0.17" y="0.083" z="-0.889" />
            </Bone> <!-- LegFoot -->
        </Bone> <!-- LeftLeg -->
    </Bone> <!-- Origin -->
</Skeleton>

The XSD That I am using is: 我正在使用的XSD是:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:complexType name="Vec3">
        <xs:attribute name="x" type="xs:float"/>
        <xs:attribute name="y" type="xs:float"/>
        <xs:attribute name="z" type="xs:float"/>
    </xs:complexType>

    <xs:element name="Bone">
        <xs:complexType mixed="true">
            <xs:sequence>
                <xs:element ref="Bone" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:element name="PivotPoint" type="Vec3" minOccurs="0" maxOccurs="1"/>
            <xs:attribute name="name" type="xsd:string" use="required"/>
            <xs:attribute name="target" type="xsd:string" />
        </xs:complexType>
    </xs:element>

    <xs:element name="Skeleton">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Bone" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="sourceSkeleton" type="xs:string" />
            <xs:attribute name="targetSkeleton" type="xs:string" />
            <xs:attribute name="version" type="xs:string" />
        </xs:complexType>
    </xs:element>

    <xs:element name="SkeletonMapping">
        <xs:complexType>
            <xs:sequence minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="Skeleton"/>
            </xs:sequence>
        </xs:complexType>
</xs:element>
</xs:schema>

The Editor I am using is Notepad++ with the XML plugins. 我使用的编辑器是带有XML插件的Notepad ++。 The XML and XSD Syntax passes validation, however I can't figure out why the XML Tool validation of the XSD says it is unable to parse the XML. XML和XSD语法通过了验证,但是我不知道为什么XSD的XML工具验证表示它无法解析XML。

If anyone knows how I can fix this please let me know, as I've tried breaking the Bone inheritance from: 如果有人知道我该如何解决此问题,请告诉我,因为我尝试破坏以下来源的Bone继承:

<Skeleton>
    <Bone>
        <Bone>
            <Bone/>
        </Bone>
    </Bone>
</Skeleton>

to

<Skeleton>
    <BoneGroup>
        <Bone>
            <BoneGroup>
                <Bone>
                    <BoneGroup>
                        <Bone/>
                    </BoneGroup>
                </Bone>
            </BoneGroup>
        </Bone>
    </BoneGroup>
</Skeleton>

, for which I created a new element BoneGroup that had a ref to Bone, and Bone had a ref to BoneGroup, but that didn't work out any better. ,为此,我创建了一个新元素BoneGroup,该元素具有对Bone的引用,而Bone具有对BoneGroup的引用,但是效果没有更好。

You XML Schema file is invalid. 您的XML模式文件无效。 Firstly, change the xsd: alias with xs: for those two attributes, since xs: is the alias you assigned for the XSD namespace. 首先,对于这两个属性,将xsd:别名更改为xs :,因为xs:是您为XSD名称空间分配的别名。 Then take the PivotPoint and put it first item in the sequence it is under now. 然后,将PivotPoint置于其下面的顺序中的第一项。

You then have to work on either the XSD or the XML to agree on what the top element name should be: SkeletalMapping or SkeletonMapping. 然后,您必须使用XSD或XML来就顶级元素名称应该是什么达成一致:SkeletalMapping或SkeletonMapping。

Then you need to fix the XML namespace; 然后,您需要修复XML名称空间。 your XSD has no target namespace whereas your XML defines the default namespace as "test"; 您的XSD没有目标名称空间,而您的XML将默认名称空间定义为“测试”; so you either add the targetNamespace and default namespace in your XSD file to be "test" or you remove the xmlns="test" in your XML file; 因此,您可以在XSD文件中添加targetNamespace和默认名称空间为“ test”,或者在XML文件中删除xmlns =“ test”; if you go with the latter, please make sure you also change the xsi:schemaLocation to xsi:noNamespaceSchemaLocation. 如果您选择后者,请确保还将xsi:schemaLocation更改为xsi:noNamespaceSchemaLocation。

I don't want to bloat the response by reposting the corrected files; 我不想通过重新发布更正后的文件来夸大响应; if you're still having troubles, please let me know and I'll attach a link with the zipped files. 如果您仍然遇到问题,请告诉我,我将在压缩文件中附加一个链接。 I did test the corrected ones and they work fine with my tooling. 我确实测试了更正的那些,并且它们与我的工具正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM