XML auto generation issue - c#

This is what my xsd looks like. Air and Car extend Segment.
<xs:element name="PNR" type="PNR" />
<xs:element minOccurs="0" maxOccurs="1" name="Segments" >
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Segment" type="Segment"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Air">
<xs:complexContent>
<xs:extension base="Segment">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Departure" type="AirportInfo" />
<xs:element minOccurs="0" maxOccurs="1" name="Arrival" type="AirportInfo" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Car">
<xs:complexContent>
<xs:extension base="Segment">
<xs:sequence>
<xs:element name="PickUp" type="AddressInfo" minOccurs="0" maxOccurs="1"/>
<xs:element name="DropOff" type="AddressInfo" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
I want an output that looks like this:
<Segments>
<Segment xsi:type="Air">
<Departure></Departure>
<Arrival></Arrival>
</Segment>
<Segment xsi:type="Car">
<PickUp></PickUp>
<DropOff></DropOff>
</Segment>
</Segments>
But when I auto-generate XML from my XSD using a tool such as xmlspy or a .net library (or whatever), I get this (Air generated multi times w/o Car).
<Segments>
<Segment xsi:type="Air">
<Departure></Departure>
<Arrival></Arrival>
</Segment>
<Segment xsi:type="Air">
<Departure></Departure>
<Arrival></Arrival>
</Segment>
</Segments>
Is there something wrong with my XSD?

Here's a technique I once used to generate XML from a set of schemas. Although it doesn't look like the right class for the job, take a look at the XmlSchemaValidator class. The trick is that you can ask it what is valid for the document you're validating at that point in the validation. You can then generate the XML that is valid at that point in the document, and validate the same XML, in order to update the XmlSchemaValidator. You can then ask it again what is valid at that point in the document, etc.
When you get to an abstract type, you'll have to know to generate one of each possible derived type.

Related

wsdl contain different links but same complex type

My Question is I have application HP Service Manager they have 2 different links to access wsdl file but wsdl file contain same data same everything.
how can i used wsdl's as service reference in C# application they import as reference but not create endpoint and binding in app.confg file because complexTyple same in both file how can Microsoft handle this issue.
<xs:complexType name="EventOutKeysType">
<xs:sequence>
<xs:element minOccurs="0" name="evsysseq" nillable="true"
type="cmn:StringType"/>
</xs:sequence>
<xs:attribute name="query" type="xs:string" use="optional"/>
<xs:attribute name="updatecounter" type="xs:long" use="optional"/>
</xs:complexType>
<xs:complexType name="EventOutInstanceType">
----------------
<xs:complexType name="EventOutKeysType">
<xs:sequence>
<xs:element minOccurs="0" name="evsysseq" nillable="true"
type="cmn:StringType"/>
</xs:sequence>
<xs:attribute name="query" type="xs:string" use="optional"/>
<xs:attribute name="updatecounter" type="xs:long" use="optional"/>
</xs:complexType>
<xs:complexType name="EventOutInstanceType">
you see they have different links but same xml,
like
..../SM/EventOut.wsdl
..../SM/EventManagement.wsdl
please advice

"The specified type was not recognized" when desearalizing a XML file using auto-generated schema

I want to explain my entire process so far, as I am new to working with XML files and hopefully someone can point out what step I messed up at. If you want to just see my question I will ask it concisely at the bottom.
I am trying to import a XML file that was generated via the accounting software Peachtree. Here is a stripped shortened version of the XML file called ITEM.xml
<PAW_Items xmlns:paw="urn:schemas-peachtree-com/paw8.02-datatypes"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema-datatypes">
<PAW_Item xsi:type="paw:item">
<ID xsi:type="paw:id">00002</ID>
<Description>Example1</Description>
<Class>1</Class>
<isInactive>TRUE</isInactive>
<Subject_to_Commission>FALSE</Subject_to_Commission>
<Description_for_Sales>Example1</Description_for_Sales>
<Sales_Prices>
<Sales_Price_Info Key="1">
<Sales_Price>5.22000</Sales_Price>
<Sales_Price_Calc>NC</Sales_Price_Calc>
<Sales_Price_Rounding>0</Sales_Price_Rounding>
<Sales_Price_Rounding_Cent>0.00000</Sales_Price_Rounding_Cent>
</Sales_Price_Info>
<Sales_Price_Info Key="2">
<Sales_Price>0.00000</Sales_Price>
<Sales_Price_Calc>NC</Sales_Price_Calc>
<Sales_Price_Rounding>0</Sales_Price_Rounding>
<Sales_Price_Rounding_Cent>0.00000</Sales_Price_Rounding_Cent>
</Sales_Price_Info>
</Sales_Prices>
<Tax_Type>0</Tax_Type>
<Last_Unit_Cost>5.22000</Last_Unit_Cost>
<Costing_Method>1</Costing_Method>
<GL_Sales_Account xsi:type="paw:id">40000</GL_Sales_Account>
<GL_Inventory_Account xsi:type="paw:id">12000</GL_Inventory_Account>
<GL_COGSSalary_Acct xsi:type="paw:id">50000</GL_COGSSalary_Acct>
<Type>SA</Type>
<Stocking_UM>BTL</Stocking_UM>
<Weight>0.00000</Weight>
<Minimum_Stock>0.00000</Minimum_Stock>
<Reorder_Quantity>0.00000</Reorder_Quantity>
<Vendor_ID xsi:type="paw:id">B&L</Vendor_ID>
<Substock_Primary_Attributes>
</Substock_Primary_Attributes>
<Substock_Secondary_Attributes>
</Substock_Secondary_Attributes>
<QuantityOnSO>0.00000</QuantityOnSO>
<QuantityOnPO>0.00000</QuantityOnPO>
<QuantityOnHand>0.00000</QuantityOnHand>
<IsTaxable>TRUE</IsTaxable>
<Print_Components>FALSE</Print_Components>
<Number_of_Components>0</Number_of_Components>
<Components>
<Component>
<Effective_Date xsi:type="paw:date"/>
<Component_Number>0</Component_Number>
<Qty_Needed>0.00000</Qty_Needed>
</Component>
</Components>
</PAW_Item>
<PAW_Item xsi:type="paw:item">
<ID xsi:type="paw:id">0001</ID>
<Description>Example2</Description>
<Class>1</Class>
<isInactive>TRUE</isInactive>
<Subject_to_Commission>FALSE</Subject_to_Commission>
<Description_for_Sales>Example2</Description_for_Sales>
<Sales_Prices>
<Sales_Price_Info Key="1">
<Sales_Price>4.39000</Sales_Price>
<Sales_Price_Calc>NC</Sales_Price_Calc>
<Sales_Price_Rounding>0</Sales_Price_Rounding>
<Sales_Price_Rounding_Cent>0.00000</Sales_Price_Rounding_Cent>
</Sales_Price_Info>
<Sales_Price_Info Key="2">
<Sales_Price>0.00000</Sales_Price>
<Sales_Price_Calc>NC</Sales_Price_Calc>
<Sales_Price_Rounding>0</Sales_Price_Rounding>
<Sales_Price_Rounding_Cent>0.00000</Sales_Price_Rounding_Cent>
</Sales_Price_Info>
</Sales_Prices>
<Tax_Type>0</Tax_Type>
<Last_Unit_Cost>4.39000</Last_Unit_Cost>
<Costing_Method>1</Costing_Method>
<GL_Sales_Account xsi:type="paw:id">40000</GL_Sales_Account>
<GL_Inventory_Account xsi:type="paw:id">12000</GL_Inventory_Account>
<GL_COGSSalary_Acct xsi:type="paw:id">50000</GL_COGSSalary_Acct>
<Type>SA</Type>
<Stocking_UM>EA</Stocking_UM>
<Weight>0.00000</Weight>
<Minimum_Stock>0.00000</Minimum_Stock>
<Reorder_Quantity>0.00000</Reorder_Quantity>
<Substock_Primary_Attributes>
</Substock_Primary_Attributes>
<Substock_Secondary_Attributes>
</Substock_Secondary_Attributes>
<QuantityOnSO>0.00000</QuantityOnSO>
<QuantityOnPO>0.00000</QuantityOnPO>
<QuantityOnHand>0.00000</QuantityOnHand>
<IsTaxable>TRUE</IsTaxable>
<Print_Components>FALSE</Print_Components>
<Number_of_Components>0</Number_of_Components>
<Components>
<Component>
<Effective_Date xsi:type="paw:date"/>
<Component_Number>0</Component_Number>
<Qty_Needed>0.00000</Qty_Needed>
</Component>
</Components>
</PAW_Item>
</PAW_Items>
The first thing I did was create a XSD file based off of the XML file using the XML Schema Definition Tool with the following command
xsd ITEM.xml
That generated two XSD files ITEM.xsd and ITEM_app1.xsd
ITEM.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="PAW_Items" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:app1="http://www.w3.org/2000/10/XMLSchema-instance">
<xs:import namespace="http://www.w3.org/2000/10/XMLSchema-instance" schemaLocation="ITEM_app1.xsd" />
<xs:element name="PAW_Items" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="PAW_Item">
<xs:complexType>
<xs:sequence>
<xs:element name="Description" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
<xs:element name="Class" type="xs:string" minOccurs="0" msdata:Ordinal="2" />
<xs:element name="isInactive" type="xs:string" minOccurs="0" msdata:Ordinal="3" />
<xs:element name="Subject_to_Commission" type="xs:string" minOccurs="0" msdata:Ordinal="4" />
<xs:element name="Description_for_Sales" type="xs:string" minOccurs="0" msdata:Ordinal="5" />
<xs:element name="Tax_Type" type="xs:string" minOccurs="0" msdata:Ordinal="6" />
<xs:element name="Last_Unit_Cost" type="xs:string" minOccurs="0" msdata:Ordinal="7" />
<xs:element name="Costing_Method" type="xs:string" minOccurs="0" msdata:Ordinal="8" />
<xs:element name="Type" type="xs:string" minOccurs="0" msdata:Ordinal="9" />
<xs:element name="Stocking_UM" type="xs:string" minOccurs="0" msdata:Ordinal="10" />
<xs:element name="Weight" type="xs:string" minOccurs="0" msdata:Ordinal="11" />
<xs:element name="Minimum_Stock" type="xs:string" minOccurs="0" msdata:Ordinal="12" />
<xs:element name="Reorder_Quantity" type="xs:string" minOccurs="0" msdata:Ordinal="13" />
<xs:element name="Substock_Primary_Attributes" type="xs:string" minOccurs="0" msdata:Ordinal="14" />
<xs:element name="Substock_Secondary_Attributes" type="xs:string" minOccurs="0" msdata:Ordinal="15" />
<xs:element name="QuantityOnSO" type="xs:string" minOccurs="0" msdata:Ordinal="16" />
<xs:element name="QuantityOnPO" type="xs:string" minOccurs="0" msdata:Ordinal="17" />
<xs:element name="QuantityOnHand" type="xs:string" minOccurs="0" msdata:Ordinal="18" />
<xs:element name="IsTaxable" type="xs:string" minOccurs="0" msdata:Ordinal="19" />
<xs:element name="Print_Components" type="xs:string" minOccurs="0" msdata:Ordinal="20" />
<xs:element name="Number_of_Components" type="xs:string" minOccurs="0" msdata:Ordinal="21" />
<xs:element name="ID" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="ID_Text" msdata:Ordinal="1">
<xs:extension base="xs:string">
<xs:attribute ref="app1:type" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="Sales_Prices" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Sales_Price_Info" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Sales_Price" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
<xs:element name="Sales_Price_Calc" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
<xs:element name="Sales_Price_Rounding" type="xs:string" minOccurs="0" msdata:Ordinal="2" />
<xs:element name="Sales_Price_Rounding_Cent" type="xs:string" minOccurs="0" msdata:Ordinal="3" />
</xs:sequence>
<xs:attribute name="Key" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GL_Sales_Account" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="GL_Sales_Account_Text" msdata:Ordinal="1">
<xs:extension base="xs:string">
<xs:attribute ref="app1:type" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="GL_Inventory_Account" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="GL_Inventory_Account_Text" msdata:Ordinal="1">
<xs:extension base="xs:string">
<xs:attribute ref="app1:type" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="GL_COGSSalary_Acct" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="GL_COGSSalary_Acct_Text" msdata:Ordinal="1">
<xs:extension base="xs:string">
<xs:attribute ref="app1:type" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="Vendor_ID" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="Vendor_ID_Text" msdata:Ordinal="1">
<xs:extension base="xs:string">
<xs:attribute ref="app1:type" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="Components" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Component" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Component_Number" type="xs:string" minOccurs="0" />
<xs:element name="Qty_Needed" type="xs:string" minOccurs="0" />
<xs:element name="Effective_Date" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute ref="app1:type" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute ref="app1:type" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
ITEM_app1.xsd:
<?xml version="1.0" standalone="yes"?>
<xs:schema targetNamespace="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:mstns="http://www.w3.org/2000/10/XMLSchema-instance" xmlns="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified" xmlns:app1="http://www.w3.org/2000/10/XMLSchema-instance">
<xs:attribute name="type" msdata:Prefix="xsi" type="xs:string" />
</xs:schema>
I then tried to just use the command xsd ITEM.xsd /c but that did not work.
E:\test>xsd ITEM.xsd /c
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.0.30319.17929]
Copyright (C) Microsoft Corporation. All rights reserved.
Schema validation warning: The 'http://www.w3.org/2000/10/XMLSchema-instance:type' attribute is not declared. Line 113, position 14.
Schema validation warning: The 'http://www.w3.org/2000/10/XMLSchema-instance:type' attribute is not declared. Line 35, position 24.
Schema validation warning: The 'http://www.w3.org/2000/10/XMLSchema-instance:type' attribute is not declared. Line 61, position 24.
Schema validation warning: The 'http://www.w3.org/2000/10/XMLSchema-instance:type' attribute is not declared. Line 70, position 24.
Schema validation warning: The 'http://www.w3.org/2000/10/XMLSchema-instance:type' attribute is not declared. Line 79, position 24.
Schema validation warning: The 'http://www.w3.org/2000/10/XMLSchema-instance:type' attribute is not declared. Line 88, position 24.
Schema validation warning: The 'http://www.w3.org/2000/10/XMLSchema-instance:type' attribute is not declared. Line 103, position 32.
Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.
Error: Error generating classes for schema 'ITEM'.
- The attribute type is missing.
If you would like more help, please type "xsd /?".
Using ITEM_app1.xsd and trying to list both files neither work, after searching for a bit I found you could list multiple files if you used the /parameters argument. So I created a parameters file with the following
<xsd xmlns='http://microsoft.com/dotnet/tools/xsd/'>
<generateClasses language='CS' namespace='Peachtree'>
<schema>ITEM.xsd</schema>
<schema>ITEM_app1.xsd</schema>
</generateClasses>
</xsd>
And that successfully created ITEM_ITEM_app1.cs (you can get a copy of the code at pastebin because posting it here makes this question go over the max post size limit)
I created this simple program to test it
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
using Peachtree;
namespace Sandbox_Console
{
public class Program
{
private static void Main(string[] args)
{
using (var file = File.OpenText(#"E:\test\ITEM.xml"))
{
var ser = new XmlSerializer(typeof(PAW_Items)); //Line 16
var result = (PAW_Items) ser.Deserialize(file);
Debugger.Break();
}
}
}
}
When I first tried to run it I got this exception
System.InvalidOperationException occurred
HResult=-2146233079
Message=Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'Peachtree.PAW_ItemsPAW_ItemSales_PricesSales_Price_Info[]' to 'Peachtree.PAW_ItemsPAW_ItemSales_PricesSales_Price_Info'
error CS0030: Cannot convert type 'Peachtree.PAW_ItemsPAW_ItemComponentsComponent[]' to 'Peachtree.PAW_ItemsPAW_ItemComponentsComponent'
error CS0029: Cannot implicitly convert type 'Peachtree.PAW_ItemsPAW_ItemSales_PricesSales_Price_Info' to 'Peachtree.PAW_ItemsPAW_ItemSales_PricesSales_Price_Info[]'
error CS0029: Cannot implicitly convert type 'Peachtree.PAW_ItemsPAW_ItemComponentsComponent' to 'Peachtree.PAW_ItemsPAW_ItemComponentsComponent[]'
Source=System.Xml
StackTrace:
at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at Sandbox_Console.Program.Main(String[] args) in e:\Code\Sandbox Console\Program.cs:line 16
InnerException:
However I found that this is a known issue with xsd.exe when you have complex types in complex types. I just changed the two classes that had [][] to [] in the generated file and that solved the issue.
My problem:
When I attempt to deserialize the file I get the following exception
System.InvalidOperationException occurred
HResult=-2146233079
Message=There is an error in XML document (4, 3).
Source=System.Xml
StackTrace:
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
at Sandbox_Console.Program.Main(String[] args) in e:\Code\Sandbox Console\Program.cs:line 16
InnerException: System.InvalidOperationException
HResult=-2146233079
Message=The specified type was not recognized: name='item', namespace='urn:schemas-peachtree-com/paw8.02-datatypes', at <PAW_Item xmlns=''>.
Source=Microsoft.GeneratedCode
StackTrace:
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderPAW_Items.Read10_PAW_ItemsPAW_Item(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderPAW_Items.Read11_PAW_Items(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderPAW_Items.Read12_PAW_Items()
InnerException:
It appears that it is blowing up on <PAW_Item xsi:type="paw:item"> and it does not know what to do with the xsi:type="paw:item" part.
If I try to add PAW_ItemsPAW_Item to the known types by changing my code to
var types = new[] {typeof (PAW_ItemsPAW_Item)}; //Line 15
var ser = new XmlSerializer(typeof(PAW_Items), types);
var result = (PAW_Items) ser.Deserialize(file);
I get the following error on the new XmlSerializer(...) line
System.InvalidOperationException occurred
HResult=-2146233079
Message=Cannot include anonymous type 'Peachtree.PAW_ItemsPAW_Item'.
Source=System.Xml
StackTrace:
at System.Xml.Serialization.XmlReflectionImporter.IncludeType(Type type, RecursionLimiter limiter)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, String defaultNamespace, String location, Evidence evidence)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, Type[] extraTypes)
at Sandbox_Console.Program.Main(String[] args) in e:\Code\Sandbox Console\Program.cs:line 15
InnerException:
What step did I miss that is causing this to happen?
Start with the first error you get which is generating the code from ITEM.xsd. xsd.exe reports that the type attribute is missing for all attributes
<xs:attribute ref="app1:type" />
within the complex types. These attributes were generated due to the xsi:type attributes in your ITEM.xml file.
I guess you want xsd.exe to generate the schema so that the specified type (paw:id, paw:item) is used for those attributes. I don't know if this works with xsd.exe, you may need to use additional command-line options on xsd.exe or use a different tool like try xsd2code for example.
Turns out if you use visual studio's (2012) designer it works fine.
I just added the .xsd file to my project and it used the tool MSDataSetGenerator and it created a DataSet that deserialized the file fine. A DataSet will work fine for my uses.

Modify xsd not to look for specific order of tags

I need to fix the error message below:
Error occured while validating xmlThe element 'UserFields' has invalid child element 'LastApproverID'. List of possible elements expected: 'FirtApproverID'.
Below is my xsd for validating the xml schema :
<xs:element name="UserFields" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="FirtApproverID" type="xs:string" minOccurs="1" />
<xs:element name="LastApproverID" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
The order of the firstapproverid and lastapproverid does not matter but the tag need to occur atleast once.
i.e it can appear
<UserFields>
<LastApproverID>123</LastApproverID>
<FirtApproverID>456</FirtApproverID>
</UserFields>
OR
<UserFields>
<FirtApproverID>456</FirtApproverID>
<LastApproverID>123</LastApproverID>
</UserFields>
The <xs:all> indicator can solve your problem.
See here for answer
Please, improve your Google skills.

WCF Web HTTP Service Help Page

I have created a simple Northwind's Product REST Web Service in WCF at /Northwind/Product. I have also enabled WCF Web HTTP Service Help Page on my service, which is at /Northwind/Product/help. I have a "GET" operation and its help page is located at: /Northwind/Product/help/operations/Get, which is your standard WCF help page that displays the Xml body, Json body, Xml Schema and Additional Xml Schemas. Pretty straight forward, right? Okay now, on to the fun stuff...
I am interested in the Xml Schema section, which is:
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Product">
<xs:sequence>
<xs:element minOccurs="0" name="CategoryID" nillable="true" type="xs:int" />
<xs:element minOccurs="0" name="Discontinued" type="xs:boolean" />
<xs:element minOccurs="0" name="ProductID" type="xs:int" />
<xs:element minOccurs="0" name="ProductName" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="QuantityPerUnit" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="ReorderLevel" nillable="true" type="xs:short" />
<xs:element minOccurs="0" name="SupplierID" nillable="true" type="xs:int" />
<xs:element minOccurs="0" name="UnitPrice" nillable="true" type="xs:decimal" />
<xs:element minOccurs="0" name="UnitsInStock" nillable="true" type="xs:short" />
<xs:element minOccurs="0" name="UnitsOnOrder" nillable="true" type="xs:short" />
</xs:sequence>
</xs:complexType>
<xs:element name="Product" nillable="true" type="Product" />
</xs:schema>
I am interested in it because of the datatypes. I want to know the datatypes of the elements. Now, I understand that's not the fundamentals of REST. However, I don't want SOAP objects here. I want to keep my services simple and loosely typed and yet still be aware of their datatypes when needed.
My question is, how can I expose just this particular section of the help file? If I cannot do that, what are my other options for achieving what I am trying to do here?
Maybe you could try with OData, as I see it it is in between of REST and SOAP.
http://msdn.microsoft.com/es-es/library/cc668794.aspx
I do not think that it is possible to be both loosly typed and a the same time know the types behind the fields.
You could send everything as a string, and then throw an exception if conversion is not possible.
There does not appear to be a tag in the xs:element tag that could be used for help infomation, http://www.w3schools.com/schema/el_element.asp

How to specify a child element in XML schema with a name but any content?

I am trying to write some XML schema code to specify that a particular element 'abc' may have a child element with name 'xyz', and that element may have any attributes, and any child elements.
At the moment I have this:
<xs:element name="abc">
<xs:complexType>
<xs:sequence>
<xs:element name="xyz">
<xs:complexType>
<xs:sequence>
<xs:any/>
</xs:sequence>
<xs:anyAttribute/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
But when I validate my XML against the schema, I get validation failures complaining about the child elements of the xyz element.
Your xs:any doesn't have any information attached to it, so it is looking for schema defined elements. If you want to be slack in your interpretation of the sub-elements, try this:
<xs:element name="abc">
<xs:complexType>
<xs:sequence>
<xs:element name="xyz">
<xs:complexType>
<xs:sequence>
<xs:any processContents="lax" />
</xs:sequence>
<xs:anyAttribute/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
This should get you past validation. If you have any expectation on the well-formedness of xyz's content, you can include a namespace using the namespace attribute for xs:any, and pull in another schema for that information.
Good luck, and I hope this helps!

Categories

Resources