xml - Deserializing cXML to C# Class -


i'm trying deserialize cxml string c# classes. however, when deserializing, can't seem other root element deserialize. how deserialize xml document seemed provide help, , using example i've managed deserialize root cxml tag, doesn't work on nested object punchoutsetuprequest object need deserialized.

my question, before showing wall of code, how can deserialize these objects cxml classes defined below without changing cxml.cs file? since standard i'd prefer not edit unless absolutely have to. code fair game. thank in advance since know topic covered far , wide across so.

i have xsd file cxml i've used xsd.exe tool convert c# classes. won't paste whole schema here avoid diluting question, can go cxml.org if need more complete picture.

my code cxml deserializes attributes , doesn't contain header or request objects defined in cxml:

using (textreader reader = new stringreader(text))             {                 try                 {                     xmlrootattribute xroot = new xmlrootattribute();                     xroot.elementname = "cxml";                     xroot.isnullable = true;                     var serializer = new xmlserializer(typeof(cxml), xroot);                     cxml = (cxml)serializer.deserialize(reader);                 }                 catch (exception ex)                 {                     string r = "";                 }             } 

my code punchoutsetuprequest deserialization. 1 throws error when sees cxml root node despite me setting xroot element punchoutsetuprequest.

using (textreader reader = new stringreader(text))             {                 try                 {                     xmlrootattribute xroot = new xmlrootattribute();                     xroot.elementname = "punchoutsetuprequest";                     xroot.isnullable = true;                     var serializer = new xmlserializer(typeof(punchoutsetuprequest), xroot);                     punchoutsetuprequest request;                     request = (punchoutsetuprequest)serializer.deserialize(reader);                 }                 catch (exception ex)                 {                     string r = "";                 }             } 

text variable value (data redacted):

<?xml version = '1.0' encoding = 'utf-8'?> <!doctype cxml system "http://xml.cxml.org/schemas/cxml/1.1.007/cxml.dtd"> <cxml version="1.1.007" xml:lang="en-us" payloadid="" timestamp="2016-01-    04t03:21:32-05:00">    <header>       <from>          <credential domain="">             <identity></identity>          </credential>       </from>       <to>          <credential domain="">             <identity></identity>          </credential>       </to>       <sender>          <credential domain="">             <identity></identity>             <sharedsecret></sharedsecret>          </credential>          <useragent></useragent>       </sender>    </header>    <request>       <punchoutsetuprequest operation="create">          <buyercookie></buyercookie>          <extrinsic name="user"></extrinsic>          <browserformpost>             <url></url>          </browserformpost>          <contact>             <name xml:lang="en-us"></name>             <email></email>          </contact>          <suppliersetup>             <url></url>          </suppliersetup>       </punchoutsetuprequest>    </request> </cxml> 

cxml class generated xsd.exe (fragmented)

[system.codedom.compiler.generatedcodeattribute("xsd", "4.0.30319.33440")] [system.serializableattribute()] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.xml.serialization.xmltypeattribute(anonymoustype = true, namespace = "http://tempuri.org/cxml")] [system.xml.serialization.xmlrootattribute(namespace = "http://tempuri.org/cxml", isnullable = false)] public partial class cxml {  private object[] itemsfield;  private string versionfield;  private string payloadidfield;  private string timestampfield;  private string langfield;  public cxml() {     this.versionfield = "1.1.010"; }  /// <remarks/> [system.xml.serialization.xmlelementattribute("header", typeof(header))] [system.xml.serialization.xmlelementattribute("message", typeof(message))] [system.xml.serialization.xmlelementattribute("request", typeof(request))] [system.xml.serialization.xmlelementattribute("response", typeof(response))] public object[] items {         {         return this.itemsfield;     }     set     {         this.itemsfield = value;     } }  /// <remarks/> [system.xml.serialization.xmlattributeattribute()] [system.componentmodel.defaultvalueattribute("1.1.010")] public string version {         {         return this.versionfield;     }     set     {         this.versionfield = value;     } }  /// <remarks/> [system.xml.serialization.xmlattributeattribute()] public string payloadid {         {         return this.payloadidfield;     }     set     {         this.payloadidfield = value;     } }  /// <remarks/> [system.xml.serialization.xmlattributeattribute()] public string timestamp {         {         return this.timestampfield;     }     set     {         this.timestampfield = value;     } }  /// <remarks/> [system.xml.serialization.xmlattributeattribute(form = system.xml.schema.xmlschemaform.qualified, namespace = "http://www.w3.org/xml/1998/namespace")] public string lang {         {         return this.langfield;     }     set     {         this.langfield = value;     } } }      /// <remarks/> [system.codedom.compiler.generatedcodeattribute("xsd", "4.0.30319.33440")] [system.serializableattribute()] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.xml.serialization.xmltypeattribute(anonymoustype = true, namespace = "http://tempuri.org/cxml")] [system.xml.serialization.xmlrootattribute(namespace = "http://tempuri.org/cxml", isnullable = false)] public partial class punchoutsetuprequest {  private buyercookie buyercookiefield;  private extrinsic[] extrinsicfield;  private browserformpost browserformpostfield;  private contact[] contactfield;  private suppliersetup suppliersetupfield;  private shipto shiptofield;  private selecteditem selecteditemfield;  private itemout[] itemoutfield;  private punchoutsetuprequestoperation operationfield;  /// <remarks/> public buyercookie buyercookie {         {         return this.buyercookiefield;     }     set     {         this.buyercookiefield = value;     } }  /// <remarks/> [system.xml.serialization.xmlelementattribute("extrinsic")] public extrinsic[] extrinsic {         {         return this.extrinsicfield;     }     set     {         this.extrinsicfield = value;     } }  /// <remarks/> public browserformpost browserformpost {         {         return this.browserformpostfield;     }     set     {         this.browserformpostfield = value;     } }  /// <remarks/> [system.xml.serialization.xmlelementattribute("contact")] public contact[] contact {         {         return this.contactfield;     }     set     {         this.contactfield = value;     } }  /// <remarks/> public suppliersetup suppliersetup {         {         return this.suppliersetupfield;     }     set     {         this.suppliersetupfield = value;     } }  /// <remarks/> public shipto shipto {         {         return this.shiptofield;     }     set     {         this.shiptofield = value;     } }  /// <remarks/> public selecteditem selecteditem {         {         return this.selecteditemfield;     }     set     {         this.selecteditemfield = value;     } }  /// <remarks/> [system.xml.serialization.xmlelementattribute("itemout")] public itemout[] itemout {         {         return this.itemoutfield;     }     set     {         this.itemoutfield = value;     } }  /// <remarks/> [system.xml.serialization.xmlattributeattribute()] public punchoutsetuprequestoperation operation {         {         return this.operationfield;     }     set     {         this.operationfield = value;     } } } 


Comments

Post a Comment

Popular posts from this blog

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -