xsd到xml - 什么是最佳做法? [英] xsd to xml - what is best practice?

查看:89
本文介绍了xsd到xml - 什么是最佳做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用wcf服务的应用程序。我使用组织提供的Web服务:

I’m developing an application where I use wcf services . I use the web service the organization offer to:


  1. 发送填充了数据的xml架构
  2. 获取可用Web服务列表
  3. 获取特定的xsd架构


我要做的是:

What I have to do is:


  1. 获取权限的xsd架构并使用此xsd生成一个用数据填充的xml
  2. 调用webservice,我可以为特定的xsd模式指定一个数字,然后获取xsd模式。然后我可以在将它发送到权限之前验证我的xml架构
  3. 使用web服务,其中我的xml字符串在wcf服务的字符串属性中,我发送xml文件到权威


我的xsd看起来(几乎)像这样:



My xsd looks (almost) like this:


<?xml version="1.0" encoding="iso-8859-1"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:br="http://www.br.se/or" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <!--title='Tittle' lang='E'-->
  <xs:element name="Schema">
    <xs:annotation>
      <xs:documentation>
        <br:txt br:lang="E" br:txttype="LEDE">
          <p>Some text</p>
        </br:txt>
      </xs:documentation>
      <xs:documentation>
 
 
…………………………
 
 
<xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" ref="Information"/>
        <xs:element minOccurs="0" ref="Payer"/>
      </xs:sequence>
      <xs:attribute fixed="105" name="numberr" type="xs:integer" use="required"/>
      <xs:attribute fixed="10360" name="externalnumberr" type="xs:integer" use="required"/>
            <xs:attribute fixed="Title" name="title" type="xs:string" use="optional"/>
      <xs:attribute fixed="4895" name="groupid" type="xs:positiveInteger" use="optional"/>
      <xs:attribute name="id" use="optional">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:enumeration value="761065">
              <xs:annotation>
                <xs:documentation>Text</xs:documentation>
              </xs:annotation>
            </xs:enumeration>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:anyAttribute/>
    </xs:complexType>
  </xs:element>
<xs:element name="Info">
    <xs:annotation>
      <xs:documentation>
        <br:txt br:lang="E" br:txttype="LEDE">
          <p>Some Text</p>
        </br:txt>
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="Task">
          <xs:annotation>
            <xs:documentation>
              <br:txt br:lang="E" br:txttype="LEDE">
                <p>Some text</p>
              </br:txt>
            </xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element ref="Year">
          <xs:annotation>
            <xs:documentation>
              <br:txt br:lang="E" br:txttype="LEDE">
                <p>Some Text</p>
              </br:txt>
            </xs:documentation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="Taskowner"/>
      </xs:sequence>
      <xs:attribute fixed="4877" name="id" type="xs:positiveInteger" use="required"/>
    </xs:complexType>
  </xs:element>
<xs:element name="TaskSpesialTask">
    <xs:annotation>
      <xs:documentation>
        <br:info br:type="some txt">1</br:info>
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="List1">
          <xs:attribute fixed="212" name="schemaid" type="xs:positiveInteger" use="required"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="List2">
    <xs:annotation>
      <xs:documentation>
        <br:info br:type="id">2</br:info>
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:length value="1"/>
      <xs:enumeration value="1">
        <xs:annotation>
          <xs:documentation>
            <br:txt br:lang="E" br:txttype="LEDE">
              <p>Some text</p>
            </br:txt>
          </xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="2">
        <xs:annotation>
          <xs:documentation>
            <br:txt br:lang="E" br:txttype="LEDE">
              <p>Some text</p>
            </br:txt>
          </xs:documentation>
        </xs:annotation>
      </xs:enumeration>
    </xs:restriction>
  </xs:simpleType>
<xs:element name="Year">
    <xs:annotation>
      <xs:documentation>
        <br:info br:type="pl">2</br:info>
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="Format">
          <xs:attribute fixed="692" name="schemaid" type="xs:positiveInteger" use="required"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="Format">
    <xs:annotation>
      <xs:documentation>
        <br:info br:type="id">6</br:info>
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:gYear"/>
  </xs:simpleType>
<xs:element name="TaskOwner">
    <xs:annotation>
      <xs:documentation>
        <br:txt br:lang="E" br:txttype="LEDE">
          <p>Some Text</p>
        </br:txt>
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="TaskoOwnerNumber">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="TaskOwnerName">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="TaskOwnerAdress
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="TaskOwnerPhone">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="TaskOwnerEmail">
          <xs:annotation>  
          </xs:annotation>
        </xs:element>
      </xs:sequence>
      <xs:attribute fixed="48" name="id" type="xs:positiveInteger" use="required"/>
    </xs:complexType>
  </xs:element>
<xs:element name="TaskOwnerNumber">
    <xs:annotation>
    </xs:annotation>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="TextFormat">
          <xs:attribute fixed="21" name="id" type="xs:positiveInteger" use="required"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="TextFormat">
    <xs:annotation>
      <xs:documentation>
        <br:info br:type="id">1</br:info>
      </xs:documentation>
      <xs:documentation>
        <br:txt br:lang="E" br:txttype="F">
          <p>Wrong number</p>
        </brreg:tekst>
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:length value="9"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:element name="TaskOwner name">
    <xs:annotation> 
    </xs:annotation>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="TextFormat">
          <xs:attribute fixed="2" name="id" type="xs:positiveInteger" use="required"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
  <xs:element name="TaskOwner Adress">
    <xs:annotation>
    </xs:annotation>
  </xs:element>
 
And so on for phone and email
 
 <xs:element name="Payers">
    <xs:annotation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="20000" minOccurs="0" ref="PayersInfo"/>
        <xs:element minOccurs="0" ref="PaymentTotal">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="NumberOfPayers">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
      </xs:sequence>
      <xs:attribute fixed="410" name="id" type="xs:positiveInteger" use="required"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="PayersInfo">
    <xs:annotation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" ref="PayerBirthNumber">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="PayerNumber">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="PayerBirthDay">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="PayerName">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="PayerAdress">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="PayerPhone">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="PayerEmail">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
        <xs:element minOccurs="0" ref="PayerSum">
          <xs:annotation>
          </xs:annotation>
        </xs:element>
      </xs:sequence>
      <xs:attribute fixed="48" name="id" type="xs:positiveInteger" use="required"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="PayerBirthNumber">
    <xs:annotation>
    </xs:annotation>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="TextFormat">
          <xs:attribute fixed="2305" name="id" type="xs:positiveInteger" use="required"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="TextFormat">
    <xs:annotation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:length value="11"/>
    </xs:restriction>
  </xs:simpleType>
 
 
And som on for PayerNumber, PayerBirthDay, PAYerNAMe, PayerAdress, PayerPhone, PayerEmail…..
 
</xs:schema>

推荐答案

Sunwerby:

Hi, Sunwerby:

你有的场景在最顶层描述了Web服务应该做什么对我来说听起来很模糊。但是让我们关注您列出的详细步骤:

The scenario you have described at the very top what the web service supposed to do sounds very vague to me. But let's focus on the detailed steps you have listed:


  1. 从权威中获取xsd架构并使用此xsd生成填充了数据$ b $的xml b
  2. 调用webservice,我可以在其中指定特定xsd模式的编号,并获取xsd模式作为回报。然后我可以在将它发送到权限之前验证我的xml架构
  3. 使用web服务,其中我的xml字符串在wcf服务的字符串属性中,我发送xml文件到权威

1。我想这是你的核心问题。但是没有标准的方法从XSD生成XML。根据不断变化生成有意义的XML数据XSD意味着人类智能或预定义规则。对于任意模式,最好使用
XSLT映射器将已知格式的XML转换为另一种格式。

1. I guess this is your core question. But there are no standard way of generating XML from XSD. To generate meaningful XML data based on ever change XSD implies human intelligence or predefined rules. For arbitrary schema, you might be better off using XSLT mapper to translate a know format of XML to another.

2。为什么不直接将XML发送到Web服务以在服务器上进行验证?

2. Why not just send the XML to the web service to validate on the server?

3。可以将2和3组合为相同的验证和提交服务吗?

3. Can 2 and 3 be combined as same validate and submit service?

如果您能更好地解释方案。在这个高级设计阶段,我们不需要关注特定的XSD格式。

If you could explain the scenario better. At this high level design stage, we don't need to concern about specific XSD format.


这篇关于xsd到xml - 什么是最佳做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆