Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

XML XSD and serisliase deserialise c#

$
0
0

XML XSD in c# Null operators

johnkeays

I have some code that a previous employee did using XSD to create an XML read.

(1) Where can I find sample XSD for Microsoft details as a user manual with examples.

(2) I have a simple sample to solve with null values.  Works okay when not null but fails when it reads XML file with null values.

I have not compiled this code but cut bits and pieces from the complex original.

(3) the file is two jars one glass jar with a lid and the other a red tin base with no lid.

I have an XML that looks like this

<?xml version="1.0" encoding="utf-8"?>

<Collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<jar>

    <jarBase>

       <material>glass</material>

   </jarBase>

  <lid>

     <lidmaterial>tin</lidmaterial>

     <colour>red</colour>

  <lid>

</jar>    

<jar>

    <jarBase>

       <material>tinny</material>

   </jarBase>

  <lid xsi:nil="true">

<jar>    

this file may not parse okay in an XMl reader.

Now I am having trouble getting the null for lids to work

// typical xsd output using ADAC namespace ADAC is public engineers data base definition as an XSD.

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd","4.0.30319.1")]

[System.SerializableAttribute()]

[System.Diagnostics.DebuggerStepThroughAttribute()]

[System.ComponentModel.DesignerCategoryAttribute("code")]

[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.adac.com.au")]

publicpartialclassjarBase{

privatestring materialField;

publicstringMaterial

{

get{

returnthis.materialField;

}

set{

this.materialField =value;

}

}

// this definition seems okay for jarBase

//

publicpartialclasslid{

privatestring lidMaterialField;

privatestring colourField;

publicstringMaterial

{

get{

returnthis.lidMaterialField;

}

set{

this.lidMaterialField =value;

}

publicstringColour

{

get{

returnthis.colourField;

}

set{

this.colourField =value;

}

}

//  this is the main routine

//

///<remarks/>

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd","4.0.30319.1")]

[System.SerializableAttribute()]

[System.Diagnostics.DebuggerStepThroughAttribute()]

[System.ComponentModel.DesignerCategoryAttribute("code")]

[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.adac.com.au")]

public partial class jar {

// alternative tried code like this

privateSystem.Nullable<jarBase> jarBaseField;

privatejarBase jarBaseField;

privatelid lidField;

publicjarBase JarBase

{

get{

returnthis.jarBaseField;

}

set{

this.jarBaseField =value;

}

publiclid Lid

{

get{

returnthis.lidField;

}

set{

this.lidField =value;

}

}

I need to get the nullable options to work okay on a struct. or a class.  currently using Visual Studio 2010 with the old AutoCAD versions.  My current version writes out the XML file with the xsi:null="true" okay but the readin fails as it tries to put the elemnt into a null pointer for the lid.

Any help welcomed....

john Keays


John Keays


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>