任何人都可以帮助我修改xsd,以便在xml的顶部添加具有两个属性的Root元素,而且xml中不需要名称空间,因此架构中也不需要
当前架构
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsdLocal="http://abcorp/json/org" targetNamespace="http://abcorp/json/org" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xsd:annotation>
<xsd:documentation>Sampleschema</xsd:documentation>
</xsd:annotation>
<xsd:element name="a" type="xsdLocal:a" />
<xsd:complexType name="aTopElmt">
<xsd:sequence>
<xsd:element name="a" type="xsdLocal:a" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="a">
<xsd:sequence>
<xsd:element name="b" type="xsdLocal:b" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="b">
<xsd:sequence>
<xsd:element name="c" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="d" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="e" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="f" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="g" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="h" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="i" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="j" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="k" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="l" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
xml当前
<?xml version="1.0" encoding="UTF-8"?>
<xsdLocal:a xmlns:xsdLocal="http://abcorp/json/org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://abcorp/json/org target.xsd ">
<xsdLocal:b>
<xsdLocal:c>xsdLocal:c</xsdLocal:c>
<xsdLocal:d>xsdLocal:d</xsdLocal:d>
<xsdLocal:e>xsdLocal:e</xsdLocal:e>
<xsdLocal:f>xsdLocal:f</xsdLocal:f>
<xsdLocal:g>xsdLocal:g</xsdLocal:g>
<xsdLocal:h>xsdLocal:h</xsdLocal:h>
<xsdLocal:i>xsdLocal:i</xsdLocal:i>
<xsdLocal:j>xsdLocal:j</xsdLocal:j>
<xsdLocal:k>xsdLocal:k</xsdLocal:k>
<xsdLocal:l>xsdLocal:l</xsdLocal:l>
</xsdLocal:b>
</xsdLocal:a>
现在必须修改架构以在顶部添加一个Root元素,并在下面添加两个属性(在xml下修改)
<?xml version="1.0" encoding="UTF-8"?>
<Root abc="123" def="234">
<a>
<b>
<c>c</c>
<d>d</d>
<e>e</e>
<f>f</f>
<g>g</g>
<h>h</h>
<i>i</i>
<j>j</j>
<k>k</k>
<l>l</l>
</b>
</a>
</Root>
请帮助我修改架构,以使修改后的xml根据该架构有效
答案 0 :(得分:0)
删除目标名称空间将消除对XML文档中名称空间的需求。以下XSD还显示了如何添加属性。
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio 2019 (https://www.liquid-technologies.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation>Sampleschema</xsd:documentation>
</xsd:annotation>
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="a" />
</xsd:sequence>
<xsd:attribute name="abc" type="xsd:string" />
<xsd:attribute name="def" type="xsd:int" />
</xsd:complexType>
</xsd:element>
<xsd:element name="a" type="a" />
<xsd:complexType name="aTopElmt">
<xsd:sequence>
<xsd:element name="a" type="a" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="a">
<xsd:sequence>
<xsd:element name="b" type="b" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="b">
<xsd:sequence>
<xsd:element name="c" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="d" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="e" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="f" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="g" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="h" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="i" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="j" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="k" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="l" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Studio 2019 (https://www.liquid-technologies.com) -->
<root abc="string" def="-2200">
<a>
<b>
<d>string</d>
<e>string</e>
<j>string</j>
<l>string</l>
</b>
</a>
</root>