xsd to xml - what is best practice?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Iâm developing an application where I use wcf services . I use the web service the organization offer to:
<ol>
Send an xml schema populated with data Get a list of available web services Get a specific xsd schema </ol>
What I have to do is:
<ol>
Get a xsd schema form the authority and use this xsd to generate a xml populated with data
Call the webservice where I can specify a number for a specific xsd schema , and get the xsd schema in return. Then I can validat my xml schema against it before I send it to the authority
Use a web service where my xml string is in a string property of the wcf service and I send the xml file to the authority
</ol>
My xsd looks (almost) like this:<br/>
<br/>
<div style="color:Black;background-color:White; <pre>
<?xml version=<span style="color:#A31515; "1.0" encoding=<span style="color:#A31515; "iso-8859-1"?>
<xs:schema attributeFormDefault=<span style="color:#A31515; "unqualified" elementFormDefault=<span style="color:#A31515; "qualified" xmlns:br=<span style="color:#A31515; "http://www.br.se/or" xmlns:xs=<span style="color:#A31515; "http://www.w3.org/2001/XMLSchema">
<!--title=<span style="color:Green; Tittle lang=E-->
<xs:element name=<span style="color:#A31515; "Schema">
<xs:annotation>
<xs:documentation>
<br:txt br:lang=<span style="color:#A31515; "E" br:txttype=<span style="color:#A31515; "LEDE">
Some text
</br:txt>
</xs:documentation>
<xs:documentation>


…………………………


<xs:complexType>
<xs:sequence>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "Information"/>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "Payer"/>
</xs:sequence>
<xs:attribute fixed=<span style="color:#A31515; "105" name=<span style="color:#A31515; "numberr" type=<span style="color:#A31515; "xs:integer" use=<span style="color:#A31515; "required"/>
<xs:attribute fixed=<span style="color:#A31515; "10360" name=<span style="color:#A31515; "externalnumberr" type=<span style="color:#A31515; "xs:integer" use=<span style="color:#A31515; "required"/>
<xs:attribute fixed=<span style="color:#A31515; "Title" name=<span style="color:#A31515; "title" type=<span style="color:#A31515; "xs:string" use=<span style="color:#A31515; "optional"/>
<xs:attribute fixed=<span style="color:#A31515; "4895" name=<span style="color:#A31515; "groupid" type=<span style="color:#A31515; "xs:positiveInteger" use=<span style="color:#A31515; "optional"/>
<xs:attribute name=<span style="color:#A31515; "id" use=<span style="color:#A31515; "optional">
<xs:simpleType>
<xs:restriction base=<span style="color:#A31515; "xs:string">
<xs:enumeration value=<span style="color:#A31515; "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=<span style="color:#A31515; "Info">
<xs:annotation>
<xs:documentation>
<br:txt br:lang=<span style="color:#A31515; "E" br:txttype=<span style="color:#A31515; "LEDE">
Some Text
</br:txt>
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref=<span style="color:#A31515; "Task">
<xs:annotation>
<xs:documentation>
<br:txt br:lang=<span style="color:#A31515; "E" br:txttype=<span style="color:#A31515; "LEDE">
Some text
</br:txt>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element ref=<span style="color:#A31515; "Year">
<xs:annotation>
<xs:documentation>
<br:txt br:lang=<span style="color:#A31515; "E" br:txttype=<span style="color:#A31515; "LEDE">
Some Text
</br:txt>
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "Taskowner"/>
</xs:sequence>
<xs:attribute fixed=<span style="color:#A31515; "4877" name=<span style="color:#A31515; "id" type=<span style="color:#A31515; "xs:positiveInteger" use=<span style="color:#A31515; "required"/>
</xs:complexType>
</xs:element>
<xs:element name=<span style="color:#A31515; "TaskSpesialTask">
<xs:annotation>
<xs:documentation>
<br:info br:type=<span style="color:#A31515; "some txt">1</br:info>
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:simpleContent>
<xs:extension base=<span style="color:#A31515; "List1">
<xs:attribute fixed=<span style="color:#A31515; "212" name=<span style="color:#A31515; "schemaid" type=<span style="color:#A31515; "xs:positiveInteger" use=<span style="color:#A31515; "required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:simpleType name=<span style="color:#A31515; "List2">
<xs:annotation>
<xs:documentation>
<br:info br:type=<span style="color:#A31515; "id">2</br:info>
</xs:documentation>
</xs:annotation>
<xs:restriction base=<span style="color:#A31515; "xs:string">
<xs:length value=<span style="color:#A31515; "1"/>
<xs:enumeration value=<span style="color:#A31515; "1">
<xs:annotation>
<xs:documentation>
<br:txt br:lang=<span style="color:#A31515; "E" br:txttype=<span style="color:#A31515; "LEDE">
Some text
</br:txt>
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value=<span style="color:#A31515; "2">
<xs:annotation>
<xs:documentation>
<br:txt br:lang=<span style="color:#A31515; "E" br:txttype=<span style="color:#A31515; "LEDE">
Some text
</br:txt>
</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:element name=<span style="color:#A31515; "Year">
<xs:annotation>
<xs:documentation>
<br:info br:type=<span style="color:#A31515; "pl">2</br:info>
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:simpleContent>
<xs:extension base=<span style="color:#A31515; "Format">
<xs:attribute fixed=<span style="color:#A31515; "692" name=<span style="color:#A31515; "schemaid" type=<span style="color:#A31515; "xs:positiveInteger" use=<span style="color:#A31515; "required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:simpleType name=<span style="color:#A31515; "Format">
<xs:annotation>
<xs:documentation>
<br:info br:type=<span style="color:#A31515; "id">6</br:info>
</xs:documentation>
</xs:annotation>
<xs:restriction base=<span style="color:#A31515; "xs:gYear"/>
</xs:simpleType>
<xs:element name=<span style="color:#A31515; "TaskOwner">
<xs:annotation>
<xs:documentation>
<br:txt br:lang=<span style="color:#A31515; "E" br:txttype=<span style="color:#A31515; "LEDE">
Some Text
</br:txt>
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref=<span style="color:#A31515; "TaskoOwnerNumber">
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "TaskOwnerName">
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref="TaskOwnerAdress
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "TaskOwnerPhone">
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "TaskOwnerEmail">
<xs:annotation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute fixed=<span style="color:#A31515; "48" name=<span style="color:#A31515; "id" type=<span style="color:#A31515; "xs:positiveInteger" use=<span style="color:#A31515; "required"/>
</xs:complexType>
</xs:element>
<xs:element name=<span style="color:#A31515; "TaskOwnerNumber">
<xs:annotation>
</xs:annotation>
<xs:complexType>
<xs:simpleContent>
<xs:extension base=<span style="color:#A31515; "TextFormat">
<xs:attribute fixed=<span style="color:#A31515; "21" name=<span style="color:#A31515; "id" type=<span style="color:#A31515; "xs:positiveInteger" use=<span style="color:#A31515; "required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:simpleType name=<span style="color:#A31515; "TextFormat">
<xs:annotation>
<xs:documentation>
<br:info br:type=<span style="color:#A31515; "id">1</br:info>
</xs:documentation>
<xs:documentation>
<br:txt br:lang=<span style="color:#A31515; "E" br:txttype=<span style="color:#A31515; "F">
Wrong number
</brreg:tekst>
</xs:documentation>
</xs:annotation>
<xs:restriction base=<span style="color:#A31515; "xs:string">
<xs:length value=<span style="color:#A31515; "9"/>
</xs:restriction>
</xs:simpleType>
<xs:element name=<span style="color:#A31515; "TaskOwner name">
<xs:annotation>
</xs:annotation>
<xs:complexType>
<xs:simpleContent>
<xs:extension base=<span style="color:#A31515; "TextFormat">
<xs:attribute fixed=<span style="color:#A31515; "2" name=<span style="color:#A31515; "id" type=<span style="color:#A31515; "xs:positiveInteger" use=<span style="color:#A31515; "required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name=<span style="color:#A31515; "TaskOwner Adress">
<xs:annotation>
</xs:annotation>
</xs:element>

<span style="color:Blue; And so <span style="color:Blue; on <span style="color:Blue; for phone <span style="color:Blue; and email

<xs:element name=<span style="color:#A31515; "Payers">
<xs:annotation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs=<span style="color:#A31515; "20000" minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "PayersInfo"/>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "PaymentTotal">
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "NumberOfPayers">
<xs:annotation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute fixed=<span style="color:#A31515; "410" name=<span style="color:#A31515; "id" type=<span style="color:#A31515; "xs:positiveInteger" use=<span style="color:#A31515; "required"/>
</xs:complexType>
</xs:element>
<xs:element name=<span style="color:#A31515; "PayersInfo">
<xs:annotation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "PayerBirthNumber">
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "PayerNumber">
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "PayerBirthDay">
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "PayerName">
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "PayerAdress">
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "PayerPhone">
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "PayerEmail">
<xs:annotation>
</xs:annotation>
</xs:element>
<xs:element minOccurs=<span style="color:#A31515; "0" ref=<span style="color:#A31515; "PayerSum">
<xs:annotation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute fixed=<span style="color:#A31515; "48" name=<span style="color:#A31515; "id" type=<span style="color:#A31515; "xs:positiveInteger" use=<span style="color:#A31515; "required"/>
</xs:complexType>
</xs:element>
<xs:element name=<span style="color:#A31515; "PayerBirthNumber">
<xs:annotation>
</xs:annotation>
<xs:complexType>
<xs:simpleContent>
<xs:extension base=<span style="color:#A31515; "TextFormat">
<xs:attribute fixed=<span style="color:#A31515; "2305" name=<span style="color:#A31515; "id" type=<span style="color:#A31515; "xs:positiveInteger" use=<span style="color:#A31515; "required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:simpleType name=<span style="color:#A31515; "TextFormat">
<xs:annotation>
</xs:annotation>
<xs:restriction base=<span style="color:#A31515; "xs:string">
<xs:length value=<span style="color:#A31515; "11"/>
</xs:restriction>
</xs:simpleType>


<span style="color:Blue; And som <span style="color:Blue; on <span style="color:Blue; for PayerNumber, PayerBirthDay, PAYerNAMe, PayerAdress, PayerPhone, PayerEmail…..

</xs:schema>
[/code]
The elements in the xsd are structured as this:<br/>
<br/>
Schema
<div style=" Info
<div style=" Year
<div style=" TaskOwner
<div style=" TaskOwnerName
<div style=" TaskOwnerAdress
<div style=" TaskOwnerPhone
<div style=" TaskOwnerEmail
<div style=" TaskOwnerNumber
<div style=" Task
<div style=" TaskSpecialTask
<div style=" TaskOrdinaryTask
<div style=" Payers
<div style=" PaymentTotal
<div style=" NumberOfPayers
<div style=" PayersInfo (list of payers)
<div style=" PayerBirtNumber
<div style=" PayerBirthDay
<div style=" PayerName
<div style=" PayerAdress
<div style=" PayerPhone
<div style=" PayerEmail
<br/>
(Pleas ignore if something is left out in the xsd - it is there just so I can explain my problem better)<br/>
<br/>
My question is, how should I generate the xml based on the xsd? Shoud I deserialize the xsd (with xsd.exe) so I get a class, create object of that class and populate it with data, and then serialize the object back to xml or should I keeping everything in the
form of an in-memory XML document like this:<br/>
<br/>
<pre>Imports System.Xml
Imports <xmlns:xsi=http://..........>

Dim xmlDocument =
<Schema xsi:noSchemaNamespaceLocation=./relativePathTo/MySchema.xsdâ>
<Info>
ââ. â..[/code]
<br/>
The xsd schema change once a year, but mostly small changes.<br/>
<br/>
What are the best approach for me, and why?<br/>
<br/>
Thanks in advance!

View the full article
 
Back
Top