修改xml架构以添加Root元素而不添加命名空间

问题描述 投票:0回答:1

任何人都可以帮我修改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根据架构有效

xml xsd schema
1个回答
0
投票

删除targetnamespace将消除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>

Graphical Representation using Liquid XML Studio

<?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>
© www.soinside.com 2019 - 2024. All rights reserved.