本文介绍了xsd 如何表示不同的 xml 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这个 XML 数据主文件

if I have this XML dataMain.xml

  <SigmodRecord>
 <issue>
  <volume>11</volume>
  <number>1</number>
 <articles>
 <article>
  <title>Annotated Bibliography on Data Design.</title>
  <initPage>45</initPage>
  <endPage>77</endPage>
 <authors>
  <author position="00">Anthony I. Wasserman</author>
  <author position="01">Karen Botnich</author>
  </authors>
  </article>
 <article>
  <title>Architecture of Future Data Base Systems.</title>
  <initPage>30</initPage>
  <endPage>44</endPage>
 <authors>
  <author position="00">Lawrence A. Rowe</author>
  <author position="01">Michael Stonebraker</author>
  </authors>
  </article>
 <article>
  <title>Database Directions III Workshop Review.</title>
  <initPage>8</initPage>
  <endPage>8</endPage>
 <authors>
  <author position="00">Tom Cook</author>
  </authors>
  </article>
 <article>
  <title>Errors in 'Process Synchronization in Database Systems'.</title>
  <initPage>9</initPage>
  <endPage>29</endPage>
 <authors>
  <author position="00">Philip A. Bernstein</author>
  <author position="01">Marco A. Casanova</author>
  <author position="02">Nathan Goodman</author>
  </authors>
  </article>
  </articles>
  </issue>
</SigmodRecord>

和这个架构 Main.xsd

and this schema Main.xsd

<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="SigmodRecord">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="issue">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="volume" type="xsd:int" />
              <xsd:element name="number" type="xsd:int" />
              <xsd:element name="articles">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element maxOccurs="unbounded" name="article">
                      <xsd:complexType>
                        <xsd:sequence>
                          <xsd:element name="title" type="xsd:string" />
                          <xsd:element name="initPage" type="xsd:int" />
                          <xsd:element name="endPage" type="xsd:int" />
                          <xsd:element name="authors">
                            <xsd:complexType>
                              <xsd:sequence>
                                <xsd:element maxOccurs="unbounded" name="author">
                                  <xsd:complexType>
                                    <xsd:attribute name="position" type="xsd:int" />
                                  </xsd:complexType>
                                </xsd:element>
                              </xsd:sequence>
                            </xsd:complexType>
                          </xsd:element>
                        </xsd:sequence>
                      </xsd:complexType>
                    </xsd:element>
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

它变成了这样的2个片段Frag1.xml:

it becomes 2 fragments like thisFrag1.xml:

 <SigmodRecord>
 <issue>
  <volume>11</volume>
  <number>1</number>
 <articles>
 <article>
  <title>Annotated Bibliography on Data Design.</title>
  <initPage>45</initPage>
  <endPage>77</endPage>
  </article>
 <article>
  <title>Architecture of Future Data Base Systems.</title>
  <initPage>30</initPage>
  <endPage>44</endPage>
  </article>
 <article>
  <title>Database Directions III Workshop Review.</title>
  <initPage>8</initPage>
  <endPage>8</endPage>
  </article>
 <article>
  <title>Errors in 'Process Synchronization in Database Systems'.</title>
  <initPage>9</initPage>
  <endPage>29</endPage>
  </article>
  </articles>
  </issue>
</SigmodRecord>

Frag2.xml:

 <SigmodRecord>
<authors>
  <author position="00">Anthony I. Wasserman</author>
  <author position="01">Karen Botnich</author>
  </authors>
 <authors>
  <author position="00">Lawrence A. Rowe</author>
  <author position="01">Michael Stonebraker</author>
  </authors>
 <authors>
  <author position="00">Tom Cook</author>
  </authors>
 <authors>
  <author position="00">Philip A. Bernstein</author>
  <author position="01">Marco A. Casanova</author>
  <author position="02">Nathan Goodman</author>
  </authors>
</SigmodRecord>

如何使用一个可以表示两个 Fragment 的模式,同时保持第一个 XML 的原始结构.换句话说,有没有办法让 Main.xsd 代表 Frag1.xsd+frag2.xsd我不想要 2 架构只有一个!?提前致谢

how can I use one schema that can represent both of Fragments with keeping the original structure of the first XML.In other words, is there any way to make Main.xsd represent Frag1.xsd+frag2.xsdI do not want 2 schema only one!!?Thanks in advance

推荐答案

您正在寻找的架构看起来像这样,

The schema you are looking for looks something like this,

<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="SigmodRecord">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="issue">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="volume" type="xsd:int" />
              <xsd:element name="number" type="xsd:int" />
              <xsd:element name="articles">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element maxOccurs="unbounded" name="article">
                      <xsd:complexType>
                        <xsd:sequence>
                          <xsd:element name="title" type="xsd:string" />
                          <xsd:element name="initPage" type="xsd:int" />
                          <xsd:element name="endPage" type="xsd:int" />
                          <xsd:element ref="authors"/>
                        </xsd:sequence>
                      </xsd:complexType>
                    </xsd:element>
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
        <xsd:element ref="authors"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="authors">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element maxOccurs="unbounded" name="author">
          <xsd:complexType>
            <xsd:attribute name="position" type="xsd:int" />
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>


此模式适用于所有 3 个 xml 片段.


This schema will work for all the 3 xml fragments.

这篇关于xsd 如何表示不同的 xml 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 05:28