XmlSerializer: deserialize against xsd generated class

Hi,

I have a schema that has an optional element, fieldTag4000Field.  If the 
element is omitted from the XML request, when it is deserialized, it will be 
null when I check it - which is fine.

What happens when the element is supplied as <fieldTag4000Field/> (empty), 
it does not equate to null.  I want to be able handle this at the 
deserialization level rahter than in my edits later.

Is there a way to alter the behavior so when I deserialize it, it is null?

I also want to add that I am calling the "CanDeserialize" method of the 
XmlSerializer object, passing in the request as a XmlNodeReader.

Thanks.

The following C# class snippet was generated by xsd.exe V2:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, 
Namespace="MyNamespace")]
    public partial class Request_TypeMessageType {
        
        private Request_TypeMessageTypeFieldTag4000 fieldTag4000Field;
        
        public Request_TypeMessageTypeFieldTag4000 FieldTag4000 {
            get {
                return this.fieldTag4000Field;
            }
            set {
                this.fieldTag4000Field = value;
            }
        }
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, 
Namespace="MyNamespace")]
    public partial class Request_TypeMessageTypeFieldTag4000 {
        
        private IDType_Type intermediaryIDCodeField;
        
        private bool intermediaryIDCodeFieldSpecified;
        
        private string intermediaryIdentifierField;
  
        public IDType_Type IntermediaryIDCode {
            get {
                return this.intermediaryIDCodeField;
            }
            set {
                this.intermediaryIDCodeField = value;
            }
        }
        

        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool IntermediaryIDCodeSpecified {
            get {
                return this.intermediaryIDCodeFieldSpecified;
            }
            set {
                this.intermediaryIDCodeFieldSpecified = value;
            }
        }
        

        public string IntermediaryIdentifier {
            get {
                return this.intermediaryIdentifierField;
            }
            set {
                this.intermediaryIdentifierField = value;
            }
        }
    }   
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="MyNamespace")]
    public enum IDType_Type {
        
        B,
        
        C,
        
        D,
        
        F,
        
        U,
    }

0
7/21/2008 5:33:02 PM
dotnet.xml 7266 articles. 0 followers. Follow

9 Replies
1323 Views

Similar Articles

[PageSpeed] 54

Unless you want to implement IXmlSerializable then I don't think you can do 
what you want. You can specify that a null element is shown as:
<myElement xsi:nil="true"/>
rather than being omitted entirely by adding the XmlElement(IsNullable = 
true) attribute to the field/property.

-- 

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"j.a. harriman" <jeffrey_no_spam_alias@nospam.nospam> wrote in message 
news:697F7C61-82AC-4387-8F04-57D200C7C703@microsoft.com...
> Hi,
>
> I have a schema that has an optional element, fieldTag4000Field.  If the
> element is omitted from the XML request, when it is deserialized, it will 
> be
> null when I check it - which is fine.
>
> What happens when the element is supplied as <fieldTag4000Field/> (empty),
> it does not equate to null.  I want to be able handle this at the
> deserialization level rahter than in my edits later.
>
> Is there a way to alter the behavior so when I deserialize it, it is null?
>
> I also want to add that I am calling the "CanDeserialize" method of the
> XmlSerializer object, passing in the request as a XmlNodeReader.
>
> Thanks.
>
> The following C# class snippet was generated by xsd.exe V2:
>
>    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
>    [System.SerializableAttribute()]
>    [System.Diagnostics.DebuggerStepThroughAttribute()]
>    [System.ComponentModel.DesignerCategoryAttribute("code")]
>    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
> Namespace="MyNamespace")]
>    public partial class Request_TypeMessageType {
>
>        private Request_TypeMessageTypeFieldTag4000 fieldTag4000Field;
>
>        public Request_TypeMessageTypeFieldTag4000 FieldTag4000 {
>            get {
>                return this.fieldTag4000Field;
>            }
>            set {
>                this.fieldTag4000Field = value;
>            }
>        }
>    }
>
>    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
>    [System.SerializableAttribute()]
>    [System.Diagnostics.DebuggerStepThroughAttribute()]
>    [System.ComponentModel.DesignerCategoryAttribute("code")]
>    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
> Namespace="MyNamespace")]
>    public partial class Request_TypeMessageTypeFieldTag4000 {
>
>        private IDType_Type intermediaryIDCodeField;
>
>        private bool intermediaryIDCodeFieldSpecified;
>
>        private string intermediaryIdentifierField;
>
>        public IDType_Type IntermediaryIDCode {
>            get {
>                return this.intermediaryIDCodeField;
>            }
>            set {
>                this.intermediaryIDCodeField = value;
>            }
>        }
>
>
>        [System.Xml.Serialization.XmlIgnoreAttribute()]
>        public bool IntermediaryIDCodeSpecified {
>            get {
>                return this.intermediaryIDCodeFieldSpecified;
>            }
>            set {
>                this.intermediaryIDCodeFieldSpecified = value;
>            }
>        }
>
>
>        public string IntermediaryIdentifier {
>            get {
>                return this.intermediaryIdentifierField;
>            }
>            set {
>                this.intermediaryIdentifierField = value;
>            }
>        }
>    }
>
>    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
>    [System.SerializableAttribute()]
>    [System.Xml.Serialization.XmlTypeAttribute(Namespace="MyNamespace")]
>    public enum IDType_Type {
>
>        B,
>
>        C,
>
>        D,
>
>        F,
>
>        U,
>    }
> 


0
7/22/2008 7:07:51 AM
Thanks for the answer Joe.

I also found some examples of using a style sheet and doing a transformation 
(Using XslCompiledTransform) of the original XmlDocument.  I've run a test 
and it seems to work in that the result is as if the original message hadn't 
had them in there.  Are there any reasons why not to implement this?

Also, I tried to locate good "beginner" examples of using IXmlSerializable 
that might be similar to what I need to do, but came up short.  I would like 
to to look at this in further detail.

Do you have any links to examples or are you aware if any of the Microsoft 
example downloads (such as SDK) have any?

Thanks. Jeff

"Joe Fawcett" wrote:

> Unless you want to implement IXmlSerializable then I don't think you can do 
> what you want. You can specify that a null element is shown as:
> <myElement xsi:nil="true"/>
> rather than being omitted entirely by adding the XmlElement(IsNullable = 
> true) attribute to the field/property.
> 
> -- 
> 
> Joe Fawcett (MVP - XML)
> 
> http://joe.fawcett.name
> 
> "j.a. harriman" <jeffrey_no_spam_alias@nospam.nospam> wrote in message 
> news:697F7C61-82AC-4387-8F04-57D200C7C703@microsoft.com...
> > Hi,
> >
> > I have a schema that has an optional element, fieldTag4000Field.  If the
> > element is omitted from the XML request, when it is deserialized, it will 
> > be
> > null when I check it - which is fine.
> >
> > What happens when the element is supplied as <fieldTag4000Field/> (empty),
> > it does not equate to null.  I want to be able handle this at the
> > deserialization level rahter than in my edits later.
> >
> > Is there a way to alter the behavior so when I deserialize it, it is null?
> >
> > I also want to add that I am calling the "CanDeserialize" method of the
> > XmlSerializer object, passing in the request as a XmlNodeReader.
> >
> > Thanks.
> >
> > The following C# class snippet was generated by xsd.exe V2:
> >
> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
> >    [System.SerializableAttribute()]
> >    [System.Diagnostics.DebuggerStepThroughAttribute()]
> >    [System.ComponentModel.DesignerCategoryAttribute("code")]
> >    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
> > Namespace="MyNamespace")]
> >    public partial class Request_TypeMessageType {
> >
> >        private Request_TypeMessageTypeFieldTag4000 fieldTag4000Field;
> >
> >        public Request_TypeMessageTypeFieldTag4000 FieldTag4000 {
> >            get {
> >                return this.fieldTag4000Field;
> >            }
> >            set {
> >                this.fieldTag4000Field = value;
> >            }
> >        }
> >    }
> >
> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
> >    [System.SerializableAttribute()]
> >    [System.Diagnostics.DebuggerStepThroughAttribute()]
> >    [System.ComponentModel.DesignerCategoryAttribute("code")]
> >    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
> > Namespace="MyNamespace")]
> >    public partial class Request_TypeMessageTypeFieldTag4000 {
> >
> >        private IDType_Type intermediaryIDCodeField;
> >
> >        private bool intermediaryIDCodeFieldSpecified;
> >
> >        private string intermediaryIdentifierField;
> >
> >        public IDType_Type IntermediaryIDCode {
> >            get {
> >                return this.intermediaryIDCodeField;
> >            }
> >            set {
> >                this.intermediaryIDCodeField = value;
> >            }
> >        }
> >
> >
> >        [System.Xml.Serialization.XmlIgnoreAttribute()]
> >        public bool IntermediaryIDCodeSpecified {
> >            get {
> >                return this.intermediaryIDCodeFieldSpecified;
> >            }
> >            set {
> >                this.intermediaryIDCodeFieldSpecified = value;
> >            }
> >        }
> >
> >
> >        public string IntermediaryIdentifier {
> >            get {
> >                return this.intermediaryIdentifierField;
> >            }
> >            set {
> >                this.intermediaryIdentifierField = value;
> >            }
> >        }
> >    }
> >
> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
> >    [System.SerializableAttribute()]
> >    [System.Xml.Serialization.XmlTypeAttribute(Namespace="MyNamespace")]
> >    public enum IDType_Type {
> >
> >        B,
> >
> >        C,
> >
> >        D,
> >
> >        F,
> >
> >        U,
> >    }
> > 
> 
> 
> 
0
7/22/2008 8:38:10 PM
Jeff

IXmlSerializable is reasonably straightforward.
The newer version needs three methods, ReadXml, WriteXml and one to find the 
Schema which is pointed to by an attribute, I normally just include the 
schema as an embedded resource.
In ReadXml you get an XmlReader containing the XML and use it to populate 
the object's fields, either reading it directly or loading it into a 
DomDocumnt/XPathDocument if that's easier. WriteXml takes the fields and 
creates an XML document.
There is an example here: http://www.devx.com/dotnet/Article/29720

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

"j.a. harriman" <jeffrey_no_spam_alias@nospam.nospam> wrote in message 
news:046D4993-D7DE-405A-814C-F5B86AC29005@microsoft.com...
> Thanks for the answer Joe.
>
> I also found some examples of using a style sheet and doing a 
> transformation
> (Using XslCompiledTransform) of the original XmlDocument.  I've run a test
> and it seems to work in that the result is as if the original message 
> hadn't
> had them in there.  Are there any reasons why not to implement this?
>
> Also, I tried to locate good "beginner" examples of using IXmlSerializable
> that might be similar to what I need to do, but came up short.  I would 
> like
> to to look at this in further detail.
>
> Do you have any links to examples or are you aware if any of the Microsoft
> example downloads (such as SDK) have any?
>
> Thanks. Jeff
>
> "Joe Fawcett" wrote:
>
>> Unless you want to implement IXmlSerializable then I don't think you can 
>> do
>> what you want. You can specify that a null element is shown as:
>> <myElement xsi:nil="true"/>
>> rather than being omitted entirely by adding the XmlElement(IsNullable =
>> true) attribute to the field/property.
>>
>> -- 
>>
>> Joe Fawcett (MVP - XML)
>>
>> http://joe.fawcett.name
>>
>> "j.a. harriman" <jeffrey_no_spam_alias@nospam.nospam> wrote in message
>> news:697F7C61-82AC-4387-8F04-57D200C7C703@microsoft.com...
>> > Hi,
>> >
>> > I have a schema that has an optional element, fieldTag4000Field.  If 
>> > the
>> > element is omitted from the XML request, when it is deserialized, it 
>> > will
>> > be
>> > null when I check it - which is fine.
>> >
>> > What happens when the element is supplied as <fieldTag4000Field/> 
>> > (empty),
>> > it does not equate to null.  I want to be able handle this at the
>> > deserialization level rahter than in my edits later.
>> >
>> > Is there a way to alter the behavior so when I deserialize it, it is 
>> > null?
>> >
>> > I also want to add that I am calling the "CanDeserialize" method of the
>> > XmlSerializer object, passing in the request as a XmlNodeReader.
>> >
>> > Thanks.
>> >
>> > The following C# class snippet was generated by xsd.exe V2:
>> >
>> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", 
>> > "2.0.50727.42")]
>> >    [System.SerializableAttribute()]
>> >    [System.Diagnostics.DebuggerStepThroughAttribute()]
>> >    [System.ComponentModel.DesignerCategoryAttribute("code")]
>> >    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
>> > Namespace="MyNamespace")]
>> >    public partial class Request_TypeMessageType {
>> >
>> >        private Request_TypeMessageTypeFieldTag4000 fieldTag4000Field;
>> >
>> >        public Request_TypeMessageTypeFieldTag4000 FieldTag4000 {
>> >            get {
>> >                return this.fieldTag4000Field;
>> >            }
>> >            set {
>> >                this.fieldTag4000Field = value;
>> >            }
>> >        }
>> >    }
>> >
>> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", 
>> > "2.0.50727.42")]
>> >    [System.SerializableAttribute()]
>> >    [System.Diagnostics.DebuggerStepThroughAttribute()]
>> >    [System.ComponentModel.DesignerCategoryAttribute("code")]
>> >    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
>> > Namespace="MyNamespace")]
>> >    public partial class Request_TypeMessageTypeFieldTag4000 {
>> >
>> >        private IDType_Type intermediaryIDCodeField;
>> >
>> >        private bool intermediaryIDCodeFieldSpecified;
>> >
>> >        private string intermediaryIdentifierField;
>> >
>> >        public IDType_Type IntermediaryIDCode {
>> >            get {
>> >                return this.intermediaryIDCodeField;
>> >            }
>> >            set {
>> >                this.intermediaryIDCodeField = value;
>> >            }
>> >        }
>> >
>> >
>> >        [System.Xml.Serialization.XmlIgnoreAttribute()]
>> >        public bool IntermediaryIDCodeSpecified {
>> >            get {
>> >                return this.intermediaryIDCodeFieldSpecified;
>> >            }
>> >            set {
>> >                this.intermediaryIDCodeFieldSpecified = value;
>> >            }
>> >        }
>> >
>> >
>> >        public string IntermediaryIdentifier {
>> >            get {
>> >                return this.intermediaryIdentifierField;
>> >            }
>> >            set {
>> >                this.intermediaryIdentifierField = value;
>> >            }
>> >        }
>> >    }
>> >
>> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", 
>> > "2.0.50727.42")]
>> >    [System.SerializableAttribute()]
>> >    [System.Xml.Serialization.XmlTypeAttribute(Namespace="MyNamespace")]
>> >    public enum IDType_Type {
>> >
>> >        B,
>> >
>> >        C,
>> >
>> >        D,
>> >
>> >        F,
>> >
>> >        U,
>> >    }
>> >
>>
>>
>> 
0
7/23/2008 7:00:44 AM
Hi Jeff

The code produced by xsd.exe, copes well with simple schema's, but if
your working against anything a bit complicated then it can cause
issues.

If you continue to have problems then I suggest you take a look at
Liquid XML Data Binder

http://www.liquid-technologies.com/Product_XmlDataBinding.aspx

This supports much more of the xsd standard, and the objects are more
strongly typed (it also comes with a free XSD editor).

Hope this helps

Regards Simon

On 23 Jul, 08:00, "Joe Fawcett" <joefawc...@newsgroup.nospam> wrote:
> Jeff
>
> IXmlSerializable is reasonably straightforward.
> The newer version needs three methods, ReadXml, WriteXml and one to find =
the
> Schema which is pointed to by an attribute, I normally just include the
> schema as an embedded resource.
> In ReadXml you get an XmlReader containing the XML and use it to populate
> the object's fields, either reading it directly or loading it into a
> DomDocumnt/XPathDocument if that's easier. WriteXml takes the fields and
> creates an XML document.
> There is an example here:http://www.devx.com/dotnet/Article/29720
>
> --
>
> Joe Fawcett (MVP - XML)http://joe.fawcett.name
>
> "j.a. harriman" <jeffrey_no_spam_al...@nospam.nospam> wrote in message
>
> news:046D4993-D7DE-405A-814C-F5B86AC29005@microsoft.com...
>
>
>
> > Thanks for the answer Joe.
>
> > I also found some examples of using a style sheet and doing a
> > transformation
> > (Using XslCompiledTransform) of the original XmlDocument. =A0I've run a=
 test
> > and it seems to work in that the result is as if the original message
> > hadn't
> > had them in there. =A0Are there any reasons why not to implement this?
>
> > Also, I tried to locate good "beginner" examples of using IXmlSerializa=
ble
> > that might be similar to what I need to do, but came up short. =A0I wou=
ld
> > like
> > to to look at this in further detail.
>
> > Do you have any links to examples or are you aware if any of the Micros=
oft
> > example downloads (such as SDK) have any?
>
> > Thanks. Jeff
>
> > "Joe Fawcett" wrote:
>
> >> Unless you want to implement IXmlSerializable then I don't think you c=
an
> >> do
> >> what you want. You can specify that a null element is shown as:
> >> <myElement xsi:nil=3D"true"/>
> >> rather than being omitted entirely by adding the XmlElement(IsNullable=
 =3D
> >> true) attribute to the field/property.
>
> >> --
>
> >> Joe Fawcett (MVP - XML)
>
> >>http://joe.fawcett.name
>
> >> "j.a. harriman" <jeffrey_no_spam_al...@nospam.nospam> wrote in message
> >>news:697F7C61-82AC-4387-8F04-57D200C7C703@microsoft.com...
> >> > Hi,
>
> >> > I have a schema that has an optional element, fieldTag4000Field. =A0=
If
> >> > the
> >> > element is omitted from the XML request, when it is deserialized, it
> >> > will
> >> > be
> >> > null when I check it - which is fine.
>
> >> > What happens when the element is supplied as <fieldTag4000Field/>
> >> > (empty),
> >> > it does not equate to null. =A0I want to be able handle this at the
> >> > deserialization level rahter than in my edits later.
>
> >> > Is there a way to alter the behavior so when I deserialize it, it is
> >> > null?
>
> >> > I also want to add that I am calling the "CanDeserialize" method of =
the
> >> > XmlSerializer object, passing in the request as a XmlNodeReader.
>
> >> > Thanks.
>
> >> > The following C# class snippet was generated by xsd.exe V2:
>
> >> > =A0 =A0[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> >> > "2.0.50727.42")]
> >> > =A0 =A0[System.SerializableAttribute()]
> >> > =A0 =A0[System.Diagnostics.DebuggerStepThroughAttribute()]
> >> > =A0 =A0[System.ComponentModel.DesignerCategoryAttribute("code")]
> >> > =A0 =A0[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=3Dtr=
ue,
> >> > Namespace=3D"MyNamespace")]
> >> > =A0 =A0public partial class Request_TypeMessageType {
>
> >> > =A0 =A0 =A0 =A0private Request_TypeMessageTypeFieldTag4000 fieldTag4=
000Field;
>
> >> > =A0 =A0 =A0 =A0public Request_TypeMessageTypeFieldTag4000 FieldTag40=
00 {
> >> > =A0 =A0 =A0 =A0 =A0 =A0get {
> >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return this.fieldTag4000Field;
> >> > =A0 =A0 =A0 =A0 =A0 =A0}
> >> > =A0 =A0 =A0 =A0 =A0 =A0set {
> >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.fieldTag4000Field =3D value;
> >> > =A0 =A0 =A0 =A0 =A0 =A0}
> >> > =A0 =A0 =A0 =A0}
> >> > =A0 =A0}
>
> >> > =A0 =A0[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> >> > "2.0.50727.42")]
> >> > =A0 =A0[System.SerializableAttribute()]
> >> > =A0 =A0[System.Diagnostics.DebuggerStepThroughAttribute()]
> >> > =A0 =A0[System.ComponentModel.DesignerCategoryAttribute("code")]
> >> > =A0 =A0[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=3Dtr=
ue,
> >> > Namespace=3D"MyNamespace")]
> >> > =A0 =A0public partial class Request_TypeMessageTypeFieldTag4000 {
>
> >> > =A0 =A0 =A0 =A0private IDType_Type intermediaryIDCodeField;
>
> >> > =A0 =A0 =A0 =A0private bool intermediaryIDCodeFieldSpecified;
>
> >> > =A0 =A0 =A0 =A0private string intermediaryIdentifierField;
>
> >> > =A0 =A0 =A0 =A0public IDType_Type IntermediaryIDCode {
> >> > =A0 =A0 =A0 =A0 =A0 =A0get {
> >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return this.intermediaryIDCodeField;
> >> > =A0 =A0 =A0 =A0 =A0 =A0}
> >> > =A0 =A0 =A0 =A0 =A0 =A0set {
> >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.intermediaryIDCodeField =3D valu=
e;
> >> > =A0 =A0 =A0 =A0 =A0 =A0}
> >> > =A0 =A0 =A0 =A0}
>
> >> > =A0 =A0 =A0 =A0[System.Xml.Serialization.XmlIgnoreAttribute()]
> >> > =A0 =A0 =A0 =A0public bool IntermediaryIDCodeSpecified {
> >> > =A0 =A0 =A0 =A0 =A0 =A0get {
> >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return this.intermediaryIDCodeFieldSp=
ecified;
> >> > =A0 =A0 =A0 =A0 =A0 =A0}
> >> > =A0 =A0 =A0 =A0 =A0 =A0set {
> >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.intermediaryIDCodeFieldSpecified=
 =3D value;
> >> > =A0 =A0 =A0 =A0 =A0 =A0}
> >> > =A0 =A0 =A0 =A0}
>
> >> > =A0 =A0 =A0 =A0public string IntermediaryIdentifier {
> >> > =A0 =A0 =A0 =A0 =A0 =A0get {
> >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return this.intermediaryIdentifierFie=
ld;
> >> > =A0 =A0 =A0 =A0 =A0 =A0}
> >> > =A0 =A0 =A0 =A0 =A0 =A0set {
> >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.intermediaryIdentifierField =3D =
value;
> >> > =A0 =A0 =A0 =A0 =A0 =A0}
> >> > =A0 =A0 =A0 =A0}
> >> > =A0 =A0}
>
> >> > =A0 =A0[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> >> > "2.0.50727.42")]
> >> > =A0 =A0[System.SerializableAttribute()]
> >> > =A0 =A0[System.Xml.Serialization.XmlTypeAttribute(Namespace=3D"MyNam=
espace")]
> >> > =A0 =A0public enum IDType_Type {
>
> >> > =A0 =A0 =A0 =A0B,
>
> >> > =A0 =A0 =A0 =A0C,
>
> >> > =A0 =A0 =A0 =A0D,
>
> >> > =A0 =A0 =A0 =A0F,
>
> >> > =A0 =A0 =A0 =A0U,
> >> > =A0 =A0}- Hide quoted text -
>
> - Show quoted text -

0
Simon4911 (2)
7/30/2008 2:32:31 PM
Simon,

Thanks for the link, I will take a look at it as it may be something we 
could use.

In the meantime, I did find a code snippet that removes the "empty" nodes 
but it removes ALL the empty nodes in the XML and I didn't state (earlier) 
that I want to do this beginning with a particular child node only.

When I use the following XPath statement in XMLSpy's XPath Evaluator, it 
locates the "empty" node mentioned in the previous posts:
/parentnode/secondchildnode//*[not(node())]

When I use the same statement in my C# code, it will not locate any empty 
nodes "under" the "secondchildnode" (count = 0):
XmlNodeList element = 
doc.SelectNodes("/parentnode/secondchildnode//*[not(node())]");

The plan is to loop through "element" and remove the nodes using the 
"ParentNode.RemoveChild" of an XmlNode - setting it to each array element, 
etc.

Any ideas as to why this is not working in .NET VS2005 2.0 framework?

Thanks.

Jeff

"Sprotty" wrote:

> Hi Jeff
> 
> The code produced by xsd.exe, copes well with simple schema's, but if
> your working against anything a bit complicated then it can cause
> issues.
> 
> If you continue to have problems then I suggest you take a look at
> Liquid XML Data Binder
> 
> http://www.liquid-technologies.com/Product_XmlDataBinding.aspx
> 
> This supports much more of the xsd standard, and the objects are more
> strongly typed (it also comes with a free XSD editor).
> 
> Hope this helps
> 
> Regards Simon
> 
> On 23 Jul, 08:00, "Joe Fawcett" <joefawc...@newsgroup.nospam> wrote:
> > Jeff
> >
> > IXmlSerializable is reasonably straightforward.
> > The newer version needs three methods, ReadXml, WriteXml and one to find the
> > Schema which is pointed to by an attribute, I normally just include the
> > schema as an embedded resource.
> > In ReadXml you get an XmlReader containing the XML and use it to populate
> > the object's fields, either reading it directly or loading it into a
> > DomDocumnt/XPathDocument if that's easier. WriteXml takes the fields and
> > creates an XML document.
> > There is an example here:http://www.devx.com/dotnet/Article/29720
> >
> > --
> >
> > Joe Fawcett (MVP - XML)http://joe.fawcett.name
> >
> > "j.a. harriman" <jeffrey_no_spam_al...@nospam.nospam> wrote in message
> >
> > news:046D4993-D7DE-405A-814C-F5B86AC29005@microsoft.com...
> >
> >
> >
> > > Thanks for the answer Joe.
> >
> > > I also found some examples of using a style sheet and doing a
> > > transformation
> > > (Using XslCompiledTransform) of the original XmlDocument.  I've run a test
> > > and it seems to work in that the result is as if the original message
> > > hadn't
> > > had them in there.  Are there any reasons why not to implement this?
> >
> > > Also, I tried to locate good "beginner" examples of using IXmlSerializable
> > > that might be similar to what I need to do, but came up short.  I would
> > > like
> > > to to look at this in further detail.
> >
> > > Do you have any links to examples or are you aware if any of the Microsoft
> > > example downloads (such as SDK) have any?
> >
> > > Thanks. Jeff
> >
> > > "Joe Fawcett" wrote:
> >
> > >> Unless you want to implement IXmlSerializable then I don't think you can
> > >> do
> > >> what you want. You can specify that a null element is shown as:
> > >> <myElement xsi:nil="true"/>
> > >> rather than being omitted entirely by adding the XmlElement(IsNullable =
> > >> true) attribute to the field/property.
> >
> > >> --
> >
> > >> Joe Fawcett (MVP - XML)
> >
> > >>http://joe.fawcett.name
> >
> > >> "j.a. harriman" <jeffrey_no_spam_al...@nospam.nospam> wrote in message
> > >>news:697F7C61-82AC-4387-8F04-57D200C7C703@microsoft.com...
> > >> > Hi,
> >
> > >> > I have a schema that has an optional element, fieldTag4000Field.  If
> > >> > the
> > >> > element is omitted from the XML request, when it is deserialized, it
> > >> > will
> > >> > be
> > >> > null when I check it - which is fine.
> >
> > >> > What happens when the element is supplied as <fieldTag4000Field/>
> > >> > (empty),
> > >> > it does not equate to null.  I want to be able handle this at the
> > >> > deserialization level rahter than in my edits later.
> >
> > >> > Is there a way to alter the behavior so when I deserialize it, it is
> > >> > null?
> >
> > >> > I also want to add that I am calling the "CanDeserialize" method of the
> > >> > XmlSerializer object, passing in the request as a XmlNodeReader.
> >
> > >> > Thanks.
> >
> > >> > The following C# class snippet was generated by xsd.exe V2:
> >
> > >> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > >> > "2.0.50727.42")]
> > >> >    [System.SerializableAttribute()]
> > >> >    [System.Diagnostics.DebuggerStepThroughAttribute()]
> > >> >    [System.ComponentModel.DesignerCategoryAttribute("code")]
> > >> >    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
> > >> > Namespace="MyNamespace")]
> > >> >    public partial class Request_TypeMessageType {
> >
> > >> >        private Request_TypeMessageTypeFieldTag4000 fieldTag4000Field;
> >
> > >> >        public Request_TypeMessageTypeFieldTag4000 FieldTag4000 {
> > >> >            get {
> > >> >                return this.fieldTag4000Field;
> > >> >            }
> > >> >            set {
> > >> >                this.fieldTag4000Field = value;
> > >> >            }
> > >> >        }
> > >> >    }
> >
> > >> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > >> > "2.0.50727.42")]
> > >> >    [System.SerializableAttribute()]
> > >> >    [System.Diagnostics.DebuggerStepThroughAttribute()]
> > >> >    [System.ComponentModel.DesignerCategoryAttribute("code")]
> > >> >    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
> > >> > Namespace="MyNamespace")]
> > >> >    public partial class Request_TypeMessageTypeFieldTag4000 {
> >
> > >> >        private IDType_Type intermediaryIDCodeField;
> >
> > >> >        private bool intermediaryIDCodeFieldSpecified;
> >
> > >> >        private string intermediaryIdentifierField;
> >
> > >> >        public IDType_Type IntermediaryIDCode {
> > >> >            get {
> > >> >                return this.intermediaryIDCodeField;
> > >> >            }
> > >> >            set {
> > >> >                this.intermediaryIDCodeField = value;
> > >> >            }
> > >> >        }
> >
> > >> >        [System.Xml.Serialization.XmlIgnoreAttribute()]
> > >> >        public bool IntermediaryIDCodeSpecified {
> > >> >            get {
> > >> >                return this.intermediaryIDCodeFieldSpecified;
> > >> >            }
> > >> >            set {
> > >> >                this.intermediaryIDCodeFieldSpecified = value;
> > >> >            }
> > >> >        }
> >
> > >> >        public string IntermediaryIdentifier {
> > >> >            get {
> > >> >                return this.intermediaryIdentifierField;
> > >> >            }
> > >> >            set {
> > >> >                this.intermediaryIdentifierField = value;
> > >> >            }
> > >> >        }
> > >> >    }
> >
> > >> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > >> > "2.0.50727.42")]
> > >> >    [System.SerializableAttribute()]
> > >> >    [System.Xml.Serialization.XmlTypeAttribute(Namespace="MyNamespace")]
> > >> >    public enum IDType_Type {
> >
> > >> >        B,
> >
> > >> >        C,
> >
> > >> >        D,
> >
> > >> >        F,
> >
> > >> >        U,
> > >> >    }- Hide quoted text -
> >
> > - Show quoted text -
> 
> 
0
7/31/2008 8:22:15 PM
You could remove the empy elements in the DOM before loading it as you
suggest.
Im not seeing a problem with that

            XmlDocument xmlDoc =3D new XmlDocument();
            xmlDoc.LoadXml("<parentnode><secondchildnode><b/></
secondchildnode></parentnode>");
            XmlNodeList xnl =3D xmlDoc.SelectNodes("//*[not(node())]");
            Debug.Assert(xnl.Count =3D=3D 1);

or you could remove it from the object model after its been loaded
(deserialized).

If you were using Liquid XML then you may be able to add code in that
would remove the empty elements as part of the de-serialization.

Cheers Simon


On 31 Jul, 21:22, j.a. harriman <jeffrey_no_spam_al...@nospam.nospam>
wrote:
> Simon,
>
> Thanks for the link, I will take a look at it as it may be something we
> could use.
>
> In the meantime, I did find a code snippet that removes the "empty" nodes
> but it removes ALL the empty nodes in the XML and I didn't state (earlier=
)
> that I want to do this beginning with a particular child node only.
>
> When I use the following XPath statement in XMLSpy's XPath Evaluator, it
> locates the "empty" node mentioned in the previous posts:
> /parentnode/secondchildnode//*[not(node())]
>
> When I use the same statement in my C# code, it will not locate any empty
> nodes "under" the "secondchildnode" (count =3D 0):
> XmlNodeList element =3D
> doc.SelectNodes("/parentnode/secondchildnode//*[not(node())]");
>
> The plan is to loop through "element" and remove the nodes using the
> "ParentNode.RemoveChild" of an XmlNode - setting it to each array element=
,
> etc.
>
> Any ideas as to why this is not working in .NET VS2005 2.0 framework?
>
> Thanks.
>
> Jeff
>
> "Sprotty" wrote:
> > Hi Jeff
>
> > The code produced by xsd.exe, copes well with simple schema's, but if
> > your working against anything a bit complicated then it can cause
> > issues.
>
> > If you continue to have problems then I suggest you take a look at
> > Liquid XML Data Binder
>
> >http://www.liquid-technologies.com/Product_XmlDataBinding.aspx
>
> > This supports much more of the xsd standard, and the objects are more
> > strongly typed (it also comes with a free XSD editor).
>
> > Hope this helps
>
> > Regards Simon
>
> > On 23 Jul, 08:00, "Joe Fawcett" <joefawc...@newsgroup.nospam> wrote:
> > > Jeff
>
> > > IXmlSerializable is reasonably straightforward.
> > > The newer version needs three methods, ReadXml, WriteXml and one to f=
ind the
> > > Schema which is pointed to by an attribute, I normally just include t=
he
> > > schema as an embedded resource.
> > > In ReadXml you get an XmlReader containing the XML and use it to popu=
late
> > > the object's fields, either reading it directly or loading it into a
> > > DomDocumnt/XPathDocument if that's easier. WriteXml takes the fields =
and
> > > creates an XML document.
> > > There is an example here:http://www.devx.com/dotnet/Article/29720
>
> > > --
>
> > > Joe Fawcett (MVP - XML)http://joe.fawcett.name
>
> > > "j.a. harriman" <jeffrey_no_spam_al...@nospam.nospam> wrote in messag=
e
>
> > >news:046D4993-D7DE-405A-814C-F5B86AC29005@microsoft.com...
>
> > > > Thanks for the answer Joe.
>
> > > > I also found some examples of using a style sheet and doing a
> > > > transformation
> > > > (Using XslCompiledTransform) of the original XmlDocument. =A0I've r=
un a test
> > > > and it seems to work in that the result is as if the original messa=
ge
> > > > hadn't
> > > > had them in there. =A0Are there any reasons why not to implement th=
is?
>
> > > > Also, I tried to locate good "beginner" examples of using IXmlSeria=
lizable
> > > > that might be similar to what I need to do, but came up short. =A0I=
 would
> > > > like
> > > > to to look at this in further detail.
>
> > > > Do you have any links to examples or are you aware if any of the Mi=
crosoft
> > > > example downloads (such as SDK) have any?
>
> > > > Thanks. Jeff
>
> > > > "Joe Fawcett" wrote:
>
> > > >> Unless you want to implement IXmlSerializable then I don't think y=
ou can
> > > >> do
> > > >> what you want. You can specify that a null element is shown as:
> > > >> <myElement xsi:nil=3D"true"/>
> > > >> rather than being omitted entirely by adding the XmlElement(IsNull=
able =3D
> > > >> true) attribute to the field/property.
>
> > > >> --
>
> > > >> Joe Fawcett (MVP - XML)
>
> > > >>http://joe.fawcett.name
>
> > > >> "j.a. harriman" <jeffrey_no_spam_al...@nospam.nospam> wrote in mes=
sage
> > > >>news:697F7C61-82AC-4387-8F04-57D200C7C703@microsoft.com...
> > > >> > Hi,
>
> > > >> > I have a schema that has an optional element, fieldTag4000Field.=
 =A0If
> > > >> > the
> > > >> > element is omitted from the XML request, when it is deserialized=
, it
> > > >> > will
> > > >> > be
> > > >> > null when I check it - which is fine.
>
> > > >> > What happens when the element is supplied as <fieldTag4000Field/=
>
> > > >> > (empty),
> > > >> > it does not equate to null. =A0I want to be able handle this at =
the
> > > >> > deserialization level rahter than in my edits later.
>
> > > >> > Is there a way to alter the behavior so when I deserialize it, i=
t is
> > > >> > null?
>
> > > >> > I also want to add that I am calling the "CanDeserialize" method=
 of the
> > > >> > XmlSerializer object, passing in the request as a XmlNodeReader.
>
> > > >> > Thanks.
>
> > > >> > The following C# class snippet was generated by xsd.exe V2:
>
> > > >> > =A0 =A0[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > > >> > "2.0.50727.42")]
> > > >> > =A0 =A0[System.SerializableAttribute()]
> > > >> > =A0 =A0[System.Diagnostics.DebuggerStepThroughAttribute()]
> > > >> > =A0 =A0[System.ComponentModel.DesignerCategoryAttribute("code")]
> > > >> > =A0 =A0[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=
=3Dtrue,
> > > >> > Namespace=3D"MyNamespace")]
> > > >> > =A0 =A0public partial class Request_TypeMessageType {
>
> > > >> > =A0 =A0 =A0 =A0private Request_TypeMessageTypeFieldTag4000 field=
Tag4000Field;
>
> > > >> > =A0 =A0 =A0 =A0public Request_TypeMessageTypeFieldTag4000 FieldT=
ag4000 {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0get {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return this.fieldTag4000Field;
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0}
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0set {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.fieldTag4000Field =3D value;
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0}
> > > >> > =A0 =A0 =A0 =A0}
> > > >> > =A0 =A0}
>
> > > >> > =A0 =A0[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > > >> > "2.0.50727.42")]
> > > >> > =A0 =A0[System.SerializableAttribute()]
> > > >> > =A0 =A0[System.Diagnostics.DebuggerStepThroughAttribute()]
> > > >> > =A0 =A0[System.ComponentModel.DesignerCategoryAttribute("code")]
> > > >> > =A0 =A0[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=
=3Dtrue,
> > > >> > Namespace=3D"MyNamespace")]
> > > >> > =A0 =A0public partial class Request_TypeMessageTypeFieldTag4000 =
{
>
> > > >> > =A0 =A0 =A0 =A0private IDType_Type intermediaryIDCodeField;
>
> > > >> > =A0 =A0 =A0 =A0private bool intermediaryIDCodeFieldSpecified;
>
> > > >> > =A0 =A0 =A0 =A0private string intermediaryIdentifierField;
>
> > > >> > =A0 =A0 =A0 =A0public IDType_Type IntermediaryIDCode {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0get {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return this.intermediaryIDCodeFie=
ld;
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0}
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0set {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.intermediaryIDCodeField =3D =
value;
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0}
> > > >> > =A0 =A0 =A0 =A0}
>
> > > >> > =A0 =A0 =A0 =A0[System.Xml.Serialization.XmlIgnoreAttribute()]
> > > >> > =A0 =A0 =A0 =A0public bool IntermediaryIDCodeSpecified {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0get {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return this.intermediaryIDCodeFie=
ldSpecified;
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0}
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0set {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.intermediaryIDCodeFieldSpeci=
fied =3D value;
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0}
> > > >> > =A0 =A0 =A0 =A0}
>
> > > >> > =A0 =A0 =A0 =A0public string IntermediaryIdentifier {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0get {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return this.intermediaryIdentifie=
rField;
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0}
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0set {
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.intermediaryIdentifierField =
=3D value;
> > > >> > =A0 =A0 =A0 =A0 =A0 =A0}
> > > >> > =A0 =A0 =A0 =A0}
> > > >> > =A0 =A0}
>
> > > >> > =A0 =A0[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > > >> > "2.0.50727.42")]
> > > >> > =A0 =A0[System.SerializableAttribute()]
> > > >> > =A0 =A0[System.Xml.Serialization.XmlTypeAttribute(Namespace=3D"M=
yNamespace")]
> > > >> > =A0 =A0public enum IDType_Type {
>
> > > >> > =A0 =A0 =A0 =A0B,
>
> > > >> > =A0 =A0 =A0 =A0C,
>
> > > >> > =A0 =A0 =A0 =A0D,
>
> > > >> > =A0 =A0 =A0 =A0F,
>
> > > >> > =A0 =A0 =A0 =A0U,
> > > >> > =A0 =A0}- Hide quoted text -
>
> > > - Show quoted text -

0
Simon4911 (2)
8/1/2008 2:02:14 PM
Building off your example, here's a respresentation of my actaul XML:
<parentnode>
	<firstchildnode>
	     <a/>
	</firstchildnode>
	<secondchildnode>
	     <b/>
	     <c>
	          <d/>
	          <e>12345</e>
	      </c>
	</secondchildnode>
</parentnode>

The XPath expression, "//*[not(node())]", removes all "empty" elements.  I 
need it to *only* remove "b" & "d" above. "a" would be left alone.

Thanks.

Jeff

"Sprotty" wrote:

> 
> You could remove the empy elements in the DOM before loading it as you
> suggest.
> Im not seeing a problem with that
> 
>             XmlDocument xmlDoc = new XmlDocument();
>             xmlDoc.LoadXml("<parentnode><secondchildnode><b/></
> secondchildnode></parentnode>");
>             XmlNodeList xnl = xmlDoc.SelectNodes("//*[not(node())]");
>             Debug.Assert(xnl.Count == 1);
> 
> or you could remove it from the object model after its been loaded
> (deserialized).
> 
> If you were using Liquid XML then you may be able to add code in that
> would remove the empty elements as part of the de-serialization.
> 
> Cheers Simon
> 
> 
> On 31 Jul, 21:22, j.a. harriman <jeffrey_no_spam_al...@nospam.nospam>
> wrote:
> > Simon,
> >
> > Thanks for the link, I will take a look at it as it may be something we
> > could use.
> >
> > In the meantime, I did find a code snippet that removes the "empty" nodes
> > but it removes ALL the empty nodes in the XML and I didn't state (earlier)
> > that I want to do this beginning with a particular child node only.
> >
> > When I use the following XPath statement in XMLSpy's XPath Evaluator, it
> > locates the "empty" node mentioned in the previous posts:
> > /parentnode/secondchildnode//*[not(node())]
> >
> > When I use the same statement in my C# code, it will not locate any empty
> > nodes "under" the "secondchildnode" (count = 0):
> > XmlNodeList element =
> > doc.SelectNodes("/parentnode/secondchildnode//*[not(node())]");
> >
> > The plan is to loop through "element" and remove the nodes using the
> > "ParentNode.RemoveChild" of an XmlNode - setting it to each array element,
> > etc.
> >
> > Any ideas as to why this is not working in .NET VS2005 2.0 framework?
> >
> > Thanks.
> >
> > Jeff
> >
> > "Sprotty" wrote:
> > > Hi Jeff
> >
> > > The code produced by xsd.exe, copes well with simple schema's, but if
> > > your working against anything a bit complicated then it can cause
> > > issues.
> >
> > > If you continue to have problems then I suggest you take a look at
> > > Liquid XML Data Binder
> >
> > >http://www.liquid-technologies.com/Product_XmlDataBinding.aspx
> >
> > > This supports much more of the xsd standard, and the objects are more
> > > strongly typed (it also comes with a free XSD editor).
> >
> > > Hope this helps
> >
> > > Regards Simon
> >
> > > On 23 Jul, 08:00, "Joe Fawcett" <joefawc...@newsgroup.nospam> wrote:
> > > > Jeff
> >
> > > > IXmlSerializable is reasonably straightforward.
> > > > The newer version needs three methods, ReadXml, WriteXml and one to find the
> > > > Schema which is pointed to by an attribute, I normally just include the
> > > > schema as an embedded resource.
> > > > In ReadXml you get an XmlReader containing the XML and use it to populate
> > > > the object's fields, either reading it directly or loading it into a
> > > > DomDocumnt/XPathDocument if that's easier. WriteXml takes the fields and
> > > > creates an XML document.
> > > > There is an example here:http://www.devx.com/dotnet/Article/29720
> >
> > > > --
> >
> > > > Joe Fawcett (MVP - XML)http://joe.fawcett.name
> >
> > > > "j.a. harriman" <jeffrey_no_spam_al...@nospam.nospam> wrote in message
> >
> > > >news:046D4993-D7DE-405A-814C-F5B86AC29005@microsoft.com...
> >
> > > > > Thanks for the answer Joe.
> >
> > > > > I also found some examples of using a style sheet and doing a
> > > > > transformation
> > > > > (Using XslCompiledTransform) of the original XmlDocument.  I've run a test
> > > > > and it seems to work in that the result is as if the original message
> > > > > hadn't
> > > > > had them in there.  Are there any reasons why not to implement this?
> >
> > > > > Also, I tried to locate good "beginner" examples of using IXmlSerializable
> > > > > that might be similar to what I need to do, but came up short.  I would
> > > > > like
> > > > > to to look at this in further detail.
> >
> > > > > Do you have any links to examples or are you aware if any of the Microsoft
> > > > > example downloads (such as SDK) have any?
> >
> > > > > Thanks. Jeff
> >
> > > > > "Joe Fawcett" wrote:
> >
> > > > >> Unless you want to implement IXmlSerializable then I don't think you can
> > > > >> do
> > > > >> what you want. You can specify that a null element is shown as:
> > > > >> <myElement xsi:nil="true"/>
> > > > >> rather than being omitted entirely by adding the XmlElement(IsNullable =
> > > > >> true) attribute to the field/property.
> >
> > > > >> --
> >
> > > > >> Joe Fawcett (MVP - XML)
> >
> > > > >>http://joe.fawcett.name
> >
> > > > >> "j.a. harriman" <jeffrey_no_spam_al...@nospam.nospam> wrote in message
> > > > >>news:697F7C61-82AC-4387-8F04-57D200C7C703@microsoft.com...
> > > > >> > Hi,
> >
> > > > >> > I have a schema that has an optional element, fieldTag4000Field.  If
> > > > >> > the
> > > > >> > element is omitted from the XML request, when it is deserialized, it
> > > > >> > will
> > > > >> > be
> > > > >> > null when I check it - which is fine.
> >
> > > > >> > What happens when the element is supplied as <fieldTag4000Field/>
> > > > >> > (empty),
> > > > >> > it does not equate to null.  I want to be able handle this at the
> > > > >> > deserialization level rahter than in my edits later.
> >
> > > > >> > Is there a way to alter the behavior so when I deserialize it, it is
> > > > >> > null?
> >
> > > > >> > I also want to add that I am calling the "CanDeserialize" method of the
> > > > >> > XmlSerializer object, passing in the request as a XmlNodeReader.
> >
> > > > >> > Thanks.
> >
> > > > >> > The following C# class snippet was generated by xsd.exe V2:
> >
> > > > >> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > > > >> > "2.0.50727.42")]
> > > > >> >    [System.SerializableAttribute()]
> > > > >> >    [System.Diagnostics.DebuggerStepThroughAttribute()]
> > > > >> >    [System.ComponentModel.DesignerCategoryAttribute("code")]
> > > > >> >    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
> > > > >> > Namespace="MyNamespace")]
> > > > >> >    public partial class Request_TypeMessageType {
> >
> > > > >> >        private Request_TypeMessageTypeFieldTag4000 fieldTag4000Field;
> >
> > > > >> >        public Request_TypeMessageTypeFieldTag4000 FieldTag4000 {
> > > > >> >            get {
> > > > >> >                return this.fieldTag4000Field;
> > > > >> >            }
> > > > >> >            set {
> > > > >> >                this.fieldTag4000Field = value;
> > > > >> >            }
> > > > >> >        }
> > > > >> >    }
> >
> > > > >> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > > > >> > "2.0.50727.42")]
> > > > >> >    [System.SerializableAttribute()]
> > > > >> >    [System.Diagnostics.DebuggerStepThroughAttribute()]
> > > > >> >    [System.ComponentModel.DesignerCategoryAttribute("code")]
> > > > >> >    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
> > > > >> > Namespace="MyNamespace")]
> > > > >> >    public partial class Request_TypeMessageTypeFieldTag4000 {
> >
> > > > >> >        private IDType_Type intermediaryIDCodeField;
> >
> > > > >> >        private bool intermediaryIDCodeFieldSpecified;
> >
> > > > >> >        private string intermediaryIdentifierField;
> >
> > > > >> >        public IDType_Type IntermediaryIDCode {
> > > > >> >            get {
> > > > >> >                return this.intermediaryIDCodeField;
> > > > >> >            }
> > > > >> >            set {
> > > > >> >                this.intermediaryIDCodeField = value;
> > > > >> >            }
> > > > >> >        }
> >
> > > > >> >        [System.Xml.Serialization.XmlIgnoreAttribute()]
> > > > >> >        public bool IntermediaryIDCodeSpecified {
> > > > >> >            get {
> > > > >> >                return this.intermediaryIDCodeFieldSpecified;
> > > > >> >            }
> > > > >> >            set {
> > > > >> >                this.intermediaryIDCodeFieldSpecified = value;
> > > > >> >            }
> > > > >> >        }
> >
> > > > >> >        public string IntermediaryIdentifier {
> > > > >> >            get {
> > > > >> >                return this.intermediaryIdentifierField;
> > > > >> >            }
> > > > >> >            set {
> > > > >> >                this.intermediaryIdentifierField = value;
> > > > >> >            }
> > > > >> >        }
> > > > >> >    }
> >
> > > > >> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > > > >> > "2.0.50727.42")]
> > > > >> >    [System.SerializableAttribute()]
> > > > >> >    [System.Xml.Serialization.XmlTypeAttribute(Namespace="MyNamespace")]
> > > > >> >    public enum IDType_Type {
> >
> > > > >> >        B,
> >
> > > > >> >        C,
> >
> > > > >> >        D,
> >
> > > > >> >        F,
> >
> > > > >> >        U,
> > > > >> >    }- Hide quoted text -
> >
> > > > - Show quoted text -
> 
> 
0
8/1/2008 3:50:00 PM
I may have tried to oversimplify my example.

The "real" XML has a number of "xmlns:" entries following the "parentnode".  
When I remove them & test, this statement, 
"/parentnode/secondchildnode//*[not(node())]", works as I was expecting.

Is there something I need to do with adding namespaces (e.g 
XmlNamespaceManager) or something else that I am unaware of?

If there are 5 namespaces in the XML do I need to add a namespace for each 
one?

How are the namespaces used in the XPath statement above?

Thanks.

Jeff

"j.a. harriman" wrote:

> Building off your example, here's a respresentation of my actaul XML:
> <parentnode>
> 	<firstchildnode>
> 	     <a/>
> 	</firstchildnode>
> 	<secondchildnode>
> 	     <b/>
> 	     <c>
> 	          <d/>
> 	          <e>12345</e>
> 	      </c>
> 	</secondchildnode>
> </parentnode>
> 
> The XPath expression, "//*[not(node())]", removes all "empty" elements.  I 
> need it to *only* remove "b" & "d" above. "a" would be left alone.
> 
> Thanks.
> 
> Jeff
> 
> "Sprotty" wrote:
> 
> > 
> > You could remove the empy elements in the DOM before loading it as you
> > suggest.
> > Im not seeing a problem with that
> > 
> >             XmlDocument xmlDoc = new XmlDocument();
> >             xmlDoc.LoadXml("<parentnode><secondchildnode><b/></
> > secondchildnode></parentnode>");
> >             XmlNodeList xnl = xmlDoc.SelectNodes("//*[not(node())]");
> >             Debug.Assert(xnl.Count == 1);
> > 
> > or you could remove it from the object model after its been loaded
> > (deserialized).
> > 
> > If you were using Liquid XML then you may be able to add code in that
> > would remove the empty elements as part of the de-serialization.
> > 
> > Cheers Simon
> > 
> > 
> > On 31 Jul, 21:22, j.a. harriman <jeffrey_no_spam_al...@nospam.nospam>
> > wrote:
> > > Simon,
> > >
> > > Thanks for the link, I will take a look at it as it may be something we
> > > could use.
> > >
> > > In the meantime, I did find a code snippet that removes the "empty" nodes
> > > but it removes ALL the empty nodes in the XML and I didn't state (earlier)
> > > that I want to do this beginning with a particular child node only.
> > >
> > > When I use the following XPath statement in XMLSpy's XPath Evaluator, it
> > > locates the "empty" node mentioned in the previous posts:
> > > /parentnode/secondchildnode//*[not(node())]
> > >
> > > When I use the same statement in my C# code, it will not locate any empty
> > > nodes "under" the "secondchildnode" (count = 0):
> > > XmlNodeList element =
> > > doc.SelectNodes("/parentnode/secondchildnode//*[not(node())]");
> > >
> > > The plan is to loop through "element" and remove the nodes using the
> > > "ParentNode.RemoveChild" of an XmlNode - setting it to each array element,
> > > etc.
> > >
> > > Any ideas as to why this is not working in .NET VS2005 2.0 framework?
> > >
> > > Thanks.
> > >
> > > Jeff
> > >
> > > "Sprotty" wrote:
> > > > Hi Jeff
> > >
> > > > The code produced by xsd.exe, copes well with simple schema's, but if
> > > > your working against anything a bit complicated then it can cause
> > > > issues.
> > >
> > > > If you continue to have problems then I suggest you take a look at
> > > > Liquid XML Data Binder
> > >
> > > >http://www.liquid-technologies.com/Product_XmlDataBinding.aspx
> > >
> > > > This supports much more of the xsd standard, and the objects are more
> > > > strongly typed (it also comes with a free XSD editor).
> > >
> > > > Hope this helps
> > >
> > > > Regards Simon
> > >
> > > > On 23 Jul, 08:00, "Joe Fawcett" <joefawc...@newsgroup.nospam> wrote:
> > > > > Jeff
> > >
> > > > > IXmlSerializable is reasonably straightforward.
> > > > > The newer version needs three methods, ReadXml, WriteXml and one to find the
> > > > > Schema which is pointed to by an attribute, I normally just include the
> > > > > schema as an embedded resource.
> > > > > In ReadXml you get an XmlReader containing the XML and use it to populate
> > > > > the object's fields, either reading it directly or loading it into a
> > > > > DomDocumnt/XPathDocument if that's easier. WriteXml takes the fields and
> > > > > creates an XML document.
> > > > > There is an example here:http://www.devx.com/dotnet/Article/29720
> > >
> > > > > --
> > >
> > > > > Joe Fawcett (MVP - XML)http://joe.fawcett.name
> > >
> > > > > "j.a. harriman" <jeffrey_no_spam_al...@nospam.nospam> wrote in message
> > >
> > > > >news:046D4993-D7DE-405A-814C-F5B86AC29005@microsoft.com...
> > >
> > > > > > Thanks for the answer Joe.
> > >
> > > > > > I also found some examples of using a style sheet and doing a
> > > > > > transformation
> > > > > > (Using XslCompiledTransform) of the original XmlDocument.  I've run a test
> > > > > > and it seems to work in that the result is as if the original message
> > > > > > hadn't
> > > > > > had them in there.  Are there any reasons why not to implement this?
> > >
> > > > > > Also, I tried to locate good "beginner" examples of using IXmlSerializable
> > > > > > that might be similar to what I need to do, but came up short.  I would
> > > > > > like
> > > > > > to to look at this in further detail.
> > >
> > > > > > Do you have any links to examples or are you aware if any of the Microsoft
> > > > > > example downloads (such as SDK) have any?
> > >
> > > > > > Thanks. Jeff
> > >
> > > > > > "Joe Fawcett" wrote:
> > >
> > > > > >> Unless you want to implement IXmlSerializable then I don't think you can
> > > > > >> do
> > > > > >> what you want. You can specify that a null element is shown as:
> > > > > >> <myElement xsi:nil="true"/>
> > > > > >> rather than being omitted entirely by adding the XmlElement(IsNullable =
> > > > > >> true) attribute to the field/property.
> > >
> > > > > >> --
> > >
> > > > > >> Joe Fawcett (MVP - XML)
> > >
> > > > > >>http://joe.fawcett.name
> > >
> > > > > >> "j.a. harriman" <jeffrey_no_spam_al...@nospam.nospam> wrote in message
> > > > > >>news:697F7C61-82AC-4387-8F04-57D200C7C703@microsoft.com...
> > > > > >> > Hi,
> > >
> > > > > >> > I have a schema that has an optional element, fieldTag4000Field.  If
> > > > > >> > the
> > > > > >> > element is omitted from the XML request, when it is deserialized, it
> > > > > >> > will
> > > > > >> > be
> > > > > >> > null when I check it - which is fine.
> > >
> > > > > >> > What happens when the element is supplied as <fieldTag4000Field/>
> > > > > >> > (empty),
> > > > > >> > it does not equate to null.  I want to be able handle this at the
> > > > > >> > deserialization level rahter than in my edits later.
> > >
> > > > > >> > Is there a way to alter the behavior so when I deserialize it, it is
> > > > > >> > null?
> > >
> > > > > >> > I also want to add that I am calling the "CanDeserialize" method of the
> > > > > >> > XmlSerializer object, passing in the request as a XmlNodeReader.
> > >
> > > > > >> > Thanks.
> > >
> > > > > >> > The following C# class snippet was generated by xsd.exe V2:
> > >
> > > > > >> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > > > > >> > "2.0.50727.42")]
> > > > > >> >    [System.SerializableAttribute()]
> > > > > >> >    [System.Diagnostics.DebuggerStepThroughAttribute()]
> > > > > >> >    [System.ComponentModel.DesignerCategoryAttribute("code")]
> > > > > >> >    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
> > > > > >> > Namespace="MyNamespace")]
> > > > > >> >    public partial class Request_TypeMessageType {
> > >
> > > > > >> >        private Request_TypeMessageTypeFieldTag4000 fieldTag4000Field;
> > >
> > > > > >> >        public Request_TypeMessageTypeFieldTag4000 FieldTag4000 {
> > > > > >> >            get {
> > > > > >> >                return this.fieldTag4000Field;
> > > > > >> >            }
> > > > > >> >            set {
> > > > > >> >                this.fieldTag4000Field = value;
> > > > > >> >            }
> > > > > >> >        }
> > > > > >> >    }
> > >
> > > > > >> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > > > > >> > "2.0.50727.42")]
> > > > > >> >    [System.SerializableAttribute()]
> > > > > >> >    [System.Diagnostics.DebuggerStepThroughAttribute()]
> > > > > >> >    [System.ComponentModel.DesignerCategoryAttribute("code")]
> > > > > >> >    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,
> > > > > >> > Namespace="MyNamespace")]
> > > > > >> >    public partial class Request_TypeMessageTypeFieldTag4000 {
> > >
> > > > > >> >        private IDType_Type intermediaryIDCodeField;
> > >
> > > > > >> >        private bool intermediaryIDCodeFieldSpecified;
> > >
> > > > > >> >        private string intermediaryIdentifierField;
> > >
> > > > > >> >        public IDType_Type IntermediaryIDCode {
> > > > > >> >            get {
> > > > > >> >                return this.intermediaryIDCodeField;
> > > > > >> >            }
> > > > > >> >            set {
> > > > > >> >                this.intermediaryIDCodeField = value;
> > > > > >> >            }
> > > > > >> >        }
> > >
> > > > > >> >        [System.Xml.Serialization.XmlIgnoreAttribute()]
> > > > > >> >        public bool IntermediaryIDCodeSpecified {
> > > > > >> >            get {
> > > > > >> >                return this.intermediaryIDCodeFieldSpecified;
> > > > > >> >            }
> > > > > >> >            set {
> > > > > >> >                this.intermediaryIDCodeFieldSpecified = value;
> > > > > >> >            }
> > > > > >> >        }
> > >
> > > > > >> >        public string IntermediaryIdentifier {
> > > > > >> >            get {
> > > > > >> >                return this.intermediaryIdentifierField;
> > > > > >> >            }
> > > > > >> >            set {
> > > > > >> >                this.intermediaryIdentifierField = value;
> > > > > >> >            }
> > > > > >> >        }
> > > > > >> >    }
> > >
> > > > > >> >    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd",
> > > > > >> > "2.0.50727.42")]
> > > > > >> >    [System.SerializableAttribute()]
> > > > > >> >    [System.Xml.Serialization.XmlTypeAttribute(Namespace="MyNamespace")]
> > > > > >> >    public enum IDType_Type {
> > >
> > > > > >> >        B,
> > >
> > > > > >> >        C,
> > >
> > > > > >> >        D,
> > >
> > > > > >> >        F,
> > >
> > > > > >> >        U,
> > > > > >> >    }- Hide quoted text -
> > >
> > > > > - Show quoted text -
> > 
> > 
0
8/1/2008 4:05:01 PM
j.a. harriman wrote:

> The "real" XML has a number of "xmlns:" entries following the "parentnode".  
> When I remove them & test, this statement, 
> "/parentnode/secondchildnode//*[not(node())]", works as I was expecting.
> 
> Is there something I need to do with adding namespaces (e.g 
> XmlNamespaceManager) or something else that I am unaware of?

If there are XML namespace declarations and you have elements or 
attributes in those namespaces you want to select with XPath then you 
indeed should use an XmlNamespaceManager and bind prefixes to the 
namespace URIs to use the prefixes in your XPath expressions to qualify 
element or attribute names. The XmlNamespaceManager is then passed as 
the second argument to the SelectNodes or SelectSingleNode calls.
If you need more concrete help then show us the relevant XML.

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
8/1/2008 4:49:18 PM
Reply:

Similar Artilces:

xsd.exe cannot generate schema
I have an xml file from which I want to generate an xsd schema and at a later stage a cs class. The xml file has a mix of defined namespaces and also an empty namespace. These are defined as follows: <silcn:silcn xmlns:silcn='http://silcn.org/200309' xmlns='http://xmlprobe.com/200312'> it contains an element <report> off the root and also a separate <Silcn:report> again off the root. When running xsd from the command line on the xml file it fails and returns an Error Message as follows: A DataTable named 'report' already belongs to this DataSet....

Disabled user account generates event log errors
I have a number of user whose accounts have been disabled as the user has left the company. However the boss in his infinite wisdom has asked that anyone emailing these people should get some sort of reply which says that they no longer work here. The only thing I can think of is to assign all of the addresses to one account with an out of office reply which gives this message. Can anyone think of a better way of doing this. (I understand that there is the possibility of a mail loop in this situation. Alternatively could I change the standard NDR notice to incorporate a line about having tri...

CAyncSocket like class design problem
Hi, I am trying to write a wrapper class for Winsock SOCKET to use it in a non-mfc project. When I checked MFC CAyncSocket class code, I found that it provides a number of overridables like OnAccept, OnConnect, OnSend etc. But in the winsock documentation, I can=92t find any messages corresponding to these events. While analyzing the call stack of OnAccept, I found that a message with id 883(I think it=92s WM_SOCKET_NOTIFY) is received by an object of class CSocketWnd. From the parameters of this message a CAyncSocket is constructed and provided the override functionality. Is the WinSock SOC...

Problem creating DataSet structure from xsd: The same table (...) cannot be the child table in two nested relations.
Suppose we have an object hierarchy in XSD. For example, let us take Control, Label, TextBox and LinkLabel windows controls. Each control has some properties which are represented as elements. Some of the elements are of complex types as well, like bounds - of type rectangle. (See full example in the bottom of the letter.) DataSet.ReadXMLSchema fails to parse such XSD file. The problem is caused by complex type as an element of the base type of hierarchy. (In the example this type is called rectangle.) More specifically, when parsing the example XSD file DataSet.ReadSchema would 1. Create tab...

XmlSerializer Collection with Collections
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different attributes, all share a base set of 4, one of the question types can have children with <option> elements, this is how the xml looks after serialization.... If you notice there is an extra <SelectionList> around the <option>'s in the final <question>, how can I write my class so I don't have this extra <SelectionList> element....my class follows, you ...

Add Webreference ( base class undefined )
Hi, When starting a CLR calls module project, I tried to add a webreference to this project. For an unknown reason, the proxy class is not created correctly, the error is base class undefined on a certain derived class. The SPROXY error is that it does not support extensions on complextypes. But a previous version of this webinterface ( that had extensions on complextypes ) worked fine. In a C# project, a can add the reference.But because the mainproject is MFC C++ and we need those MFC objects to fill up the objects, a C# class is not possible without a wrapper around it. I think this is a b...

class diagram
I have a short program that is just a class derived from CDialog. I was told to make a class diagram from it. Is it customary to include CWnd, CCmdTarget, and CObject on such diagrams? Also, is there any way to have VC++ or some other program automatically generate such diagrams? Thank you. Hi Bob, Yes you would include all the parent classes in your class diagram (I'm assuming your'e using UML?) as that will show the inheritance stuff I'm not sure about programs but I know of one documentation tool called DOxygen which also generates simple class diagrams in the document...

Generate a random list
I am trying to achieve the following. Column A has a list of names. I would like to randomly assign a letter to each name in column B , however as column a is a variable the list size will vary. Any help is most appreciated Let's start with using an out-of-the-way location of your sheet to set up the alphabet. Say in Z1 to Z26, you enter the alphabet. In Y1, enter this formula: =Rand() And copy it down to Y26. With your list starting in A1, enter this formula in B1: =INDEX(Z$1:Z$26,RANK(Y1,Y$1:Y$26)) I don't see where the length of your list is a problem. Just copy the formula ...

Create XSD (or something else) from XML to validate
Hello everybody, here is my question (sorry for my english) I know I am going to receive some xml=B4s. I know the structure they are going to have. As an example: <?xml version=3D"1.0" encoding=3D"UTF-8"?> <soapenv:Envelope xmlns:soapenv=3D"http://schemas.xmlsoap.org/soap/ envelope/" xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <gi-test xmlns=3D"urn:pm_interfaz_soap2"> <cod-user xmlns=3D"">TESTUSER</cod-user&...

Workflow generated email for reassignment of Opportunity
We have a CSR that inputs Opportunities in to CRM and then assigns them to the appropriate Salesperson based on Account Ownership. I tried creating a workflow process that automatically sends an email to the Account Owner that an Opportunity has been assigned to them. Unfortunately the recipient box is grayed out and by default the email is sent to the Account. Is there a workflow process in place that can handle my intentions? Actually, you can send email to designated recipients with Workfow, you just can't use a template. For some reason, it was setup this way. You could code a ...

unhelpful deserialization error
This code - private static void Test() { using (XmlReader reader = XmlReader.Create("ExecutionPlan.xml", new XmlReaderSettings())) { XmlSerializer serializer = new XmlSerializer(typeof(TEST.ShowPlanXML)); ShowPlanXML plan = (TEST.ShowPlanXML)serializer.Deserialize(reader); Console.WriteLine(plan.Version); } } throws this exception - "Could not load type 'TEST.ShowPlanXML' from assembly 'TEST, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.":"TEST.ShowPlanXML ShowPlanXML is a 8000+ lin...

Pivot Tables + Color + Dynamic Content generation and display
I have a dynamically generated pivot table (generated from actions in another spreadsheet - number of rows and location keeps changing - cant use conditional formatting). The data I currently have displayed on the pivot table is: Resource Project Allocation Jan Allocation Feb -------- ------- -------------- -------------- Resource1 Project1 0.5 0.5 Resource1 Project1 0.25 0.5 Resource1 Total 0.75 1.0 Resource2 Project1... .. I need to (1) Highlight, in red, items where Resource totals are less than 1.00. e.g. Resource 1 Total. Just...

Build error when adding a message handler to a CWinThread derived class
This one might be simple, but I'm scratching my head a bit. I've got a class derived from CWinThread, and when I want it to do something I'll post a message to it MyWinThreadObj->PostThreadMessage(MyMessage, param1, param2); and declare a function handler as public or protected or whatever LRESULT Handler(WPARAM, LPARAM); and in the message map for the class : BEGIN_MESSAGE_MAP(MyClass, CWinThread) ON_MESSAGE(WM_MYMESSAGE,Handler) END_MESSAGE_MAP() and the compliler is telling me: error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall MyClass...

XmlSerializer
I'm having a basic problem with the XmlSerializer & i'm at my wits end trying to sort it out i have a basic clas <Serializable()> Class Tes Public Name as Strin End Clas when this serializes i wan <Test><Name>Value</Name></Test the problem is if i use the XmlSerializer clas Dim t as Tes t.Name="Value Dim sb As New StringBuilde Dim sw As New StringWriter(sb Dim Serializer As New XmlSerializer(Message.GetType Serializer.Serialize(sw, t Serializer = Nothin Console.Write(sb.ToStr...

XSD.EXE and DebuggerStepThroughAttribute
I used XSD.exe generated classes. These are partial classses. Nice! I can enhance the class by adding my specialized code/methods a seperate file. But with one problem: The clasess generated are marked with DebuggerStepThroughAttribute. That causes my specialized code's break point being skipped. I know I can, in IDE, set not just My Own Code being debugged. But is there a better way? I want DebuggerStepThroughAttribute set on generated methods instead of the classes. ...

Reports Generating Incorrect Data
Hello, I have created a database with 3 forms, 3 reports and multiple queries. On the one form there are three drop down boxes (Analyst, Reviewer, Year) and there are 3 cmd buttons (Detailed Report, Summary Report, Exit). When I click either of the Report cmd buttons it generates a report for each record in the database rather then one report based on the selectiosn I made from the drop down boxes. For example I have two records in the database for testing purposes. If I select Matt for the analyst and Angella for the reviewer then hit one of the report buttons it gives me a report fo...

Some stock trader is giving a free class
This guy I've been following, the stock stalker, absolutely nailed GNBT right at the bottom. Now it looks like he is giving a free charting class on how he pulled it off. Thought you traders might want to check it out. http://www.thestockstalker.com/primer.html?osadcampaign=fwg ...

XmlSerializer and shared objects (or How to generate IDREFs using XmlSerializer)
This is a multi-part message in MIME format. ------=_NextPart_000_007F_01C34AC1.11D4FB20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am trying to find a solution that will allow me to use XmlSerializer = to serialize/deserialize a collection of objects where a given object is = shared between two or more other objects, and not create duplicate XML = representations of the shared object, but instead use IDREFs to refer to = the shared object. The XML I'm trying to produce is as follows (where "href" is an IDREF): <...

automatically generate serial numbers in inventory transactions
Serial numbers can be automatically generated in PO receipts and MO receipts. This same process should be extended to Inventory Adjustment Transactions where the transaction is a receipt. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Busine...

"Object or class does not support the set of events" Quick Question
All, I built a MS Access database in MS Access 2003, which I have set up in a shared folder. I have a form with some standard components such as text boxs, bottons. When a user updates the form I wish to record the time/date and username in the record. I have posted a copy of the code I'm using for the "BeforeUpdate" event below. Now this works fine on my machine and updates without a problem. However when a user on another machine (also using MS Access 2003) tries to update the same field, he gets the following error: "The expression Before Update you entered as the eve...

XSD Validation of an XML in C#
I am trying to develop a C# Webservice where I validate incoming XML files using an XSD schema. 3 of the parameters may have greater than 100 valid entries. These are stored in a SQL Server DB. Rather than use enumerations in teh XSD for the validation is there another way I can do this? ...

XmlSerializer and inherited objects
Hi I have a hirachy of classes which are Message(base), then FileMessage and ChatMessage (extended) I want to serialize the objects and when i am deserizaling i dont know if i am getting FileMessage or ChatMessage. So how to get that object and use it I have written following code for serialization public void Send(Message message) { NetworkStream netWorkStream=null; try { XmlSerializer serializer=new XmlSerializer(message.GetType()); netWorkStream=new NetworkStream(_clientSocket); Stream stream=(Stream)netWorkStream; serializer.Serialize(stream,message); } finally { netWorkStrea...

XMLSerializer Serialize
Iam trying to create a xml file by serializing a custom business object. Iam using a xmltextwriter, but the problem there are invalid characters at the end of the generated file anyone knows a way around it ? tia Dim myStream As New IO.MemoryStream Dim myXMLWriter As New System.Xml.XmlTextWriter(myStream, System.Text.Encoding.UTF8) myXMLWriter.Formatting = System.Xml.Formatting.Indented Dim myShipments As OrderShipments myShipments = CType(myOrder.OrderAddresses(0), COrderAddress).Shipments myShipments.ToXML(myXMLWriter) ...

XmlSerializer help
Hi, I have a class: public class Note { public string name; public string information; } And i Serialize this class, but want to Serialize it to an XmlDocument which will contain many of these elements. How do i do this? Thank you, Tim. Timothy, take a look at Chris Lovett's XmlNodeWriter on www.gotdotnet.com [0]. Simply pass the node where you want to insert the serialized XML into the XmlDocument to an XmlNodeWriter and pass the XmlNodeWriter to the Serialize method. -- HTH Christoph Schittko [MVP] Software Architect, .NET Mentor [0] http://gotdotnet.com/Communit...

Problems with XmlSerializer and namespaces
I have an object, Teacher, that has a namespace. Let's call it http://foo. Teacher has a child object called Name, composed of String first, middle, last, etc. Problem I have is when I try to deserialize it. When I deserialize a single Teacher, it works when I put the namespace on the Teacher element. However, if I have just the namespace on Teacher, it will deserialize fine as Teacher. *However*, if I try to deserialize an ArrayOfTeacher, Teacher.Name doesn't deserialize (it's null); without the array, it's OK. What I wound up doing was serializing both a Teacher ...