473,804 Members | 3,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlSerializer: deserialize against xsd generated class

Hi,

I have a schema that has an optional element, fieldTag4000Fie ld. 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 <fieldTag4000Fi eld/(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.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageType {

private Request_TypeMes sageTypeFieldTa g4000 fieldTag4000Fie ld;

public Request_TypeMes sageTypeFieldTa g4000 FieldTag4000 {
get {
return this.fieldTag40 00Field;
}
set {
this.fieldTag40 00Field = value;
}
}
}

[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageTypeFieldTa g4000 {

private IDType_Type intermediaryIDC odeField;

private bool intermediaryIDC odeFieldSpecifi ed;

private string intermediaryIde ntifierField;

public IDType_Type IntermediaryIDC ode {
get {
return this.intermedia ryIDCodeField;
}
set {
this.intermedia ryIDCodeField = value;
}
}
[System.Xml.Seri alization.XmlIg noreAttribute()]
public bool IntermediaryIDC odeSpecified {
get {
return this.intermedia ryIDCodeFieldSp ecified;
}
set {
this.intermedia ryIDCodeFieldSp ecified = value;
}
}
public string IntermediaryIde ntifier {
get {
return this.intermedia ryIdentifierFie ld;
}
set {
this.intermedia ryIdentifierFie ld = value;
}
}
}

[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="MyNames pace")]
public enum IDType_Type {

B,

C,

D,

F,

U,
}

Jul 21 '08 #1
9 3301
Unless you want to implement IXmlSerializabl e 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(IsNu llable =
true) attribute to the field/property.

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"j.a. harriman" <je************ *******@nospam. nospamwrote in message
news:69******** *************** ***********@mic rosoft.com...
Hi,

I have a schema that has an optional element, fieldTag4000Fie ld. 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 <fieldTag4000Fi eld/(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.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageType {

private Request_TypeMes sageTypeFieldTa g4000 fieldTag4000Fie ld;

public Request_TypeMes sageTypeFieldTa g4000 FieldTag4000 {
get {
return this.fieldTag40 00Field;
}
set {
this.fieldTag40 00Field = value;
}
}
}

[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageTypeFieldTa g4000 {

private IDType_Type intermediaryIDC odeField;

private bool intermediaryIDC odeFieldSpecifi ed;

private string intermediaryIde ntifierField;

public IDType_Type IntermediaryIDC ode {
get {
return this.intermedia ryIDCodeField;
}
set {
this.intermedia ryIDCodeField = value;
}
}
[System.Xml.Seri alization.XmlIg noreAttribute()]
public bool IntermediaryIDC odeSpecified {
get {
return this.intermedia ryIDCodeFieldSp ecified;
}
set {
this.intermedia ryIDCodeFieldSp ecified = value;
}
}
public string IntermediaryIde ntifier {
get {
return this.intermedia ryIdentifierFie ld;
}
set {
this.intermedia ryIdentifierFie ld = value;
}
}
}

[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="MyNames pace")]
public enum IDType_Type {

B,

C,

D,

F,

U,
}

Jul 22 '08 #2
Thanks for the answer Joe.

I also found some examples of using a style sheet and doing a transformation
(Using XslCompiledTran sform) 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 IXmlSerializabl e
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 IXmlSerializabl e 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(IsNu llable =
true) attribute to the field/property.

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"j.a. harriman" <je************ *******@nospam. nospamwrote in message
news:69******** *************** ***********@mic rosoft.com...
Hi,

I have a schema that has an optional element, fieldTag4000Fie ld. 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 <fieldTag4000Fi eld/(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.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageType {

private Request_TypeMes sageTypeFieldTa g4000 fieldTag4000Fie ld;

public Request_TypeMes sageTypeFieldTa g4000 FieldTag4000 {
get {
return this.fieldTag40 00Field;
}
set {
this.fieldTag40 00Field = value;
}
}
}

[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageTypeFieldTa g4000 {

private IDType_Type intermediaryIDC odeField;

private bool intermediaryIDC odeFieldSpecifi ed;

private string intermediaryIde ntifierField;

public IDType_Type IntermediaryIDC ode {
get {
return this.intermedia ryIDCodeField;
}
set {
this.intermedia ryIDCodeField = value;
}
}
[System.Xml.Seri alization.XmlIg noreAttribute()]
public bool IntermediaryIDC odeSpecified {
get {
return this.intermedia ryIDCodeFieldSp ecified;
}
set {
this.intermedia ryIDCodeFieldSp ecified = value;
}
}
public string IntermediaryIde ntifier {
get {
return this.intermedia ryIdentifierFie ld;
}
set {
this.intermedia ryIdentifierFie ld = value;
}
}
}

[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="MyNames pace")]
public enum IDType_Type {

B,

C,

D,

F,

U,
}


Jul 22 '08 #3
Jeff

IXmlSerializabl e 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" <je************ *******@nospam. nospamwrote in message
news:04******** *************** ***********@mic rosoft.com...
Thanks for the answer Joe.

I also found some examples of using a style sheet and doing a
transformation
(Using XslCompiledTran sform) 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 IXmlSerializabl e
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 IXmlSerializabl e 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(IsNu llable =
true) attribute to the field/property.

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"j.a. harriman" <je************ *******@nospam. nospamwrote in message
news:69******* *************** ************@mi crosoft.com...
Hi,

I have a schema that has an optional element, fieldTag4000Fie ld. 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 <fieldTag4000Fi eld/>
(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.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageType {

private Request_TypeMes sageTypeFieldTa g4000 fieldTag4000Fie ld;

public Request_TypeMes sageTypeFieldTa g4000 FieldTag4000 {
get {
return this.fieldTag40 00Field;
}
set {
this.fieldTag40 00Field = value;
}
}
}

[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageTypeFieldTa g4000 {

private IDType_Type intermediaryIDC odeField;

private bool intermediaryIDC odeFieldSpecifi ed;

private string intermediaryIde ntifierField;

public IDType_Type IntermediaryIDC ode {
get {
return this.intermedia ryIDCodeField;
}
set {
this.intermedia ryIDCodeField = value;
}
}
[System.Xml.Seri alization.XmlIg noreAttribute()]
public bool IntermediaryIDC odeSpecified {
get {
return this.intermedia ryIDCodeFieldSp ecified;
}
set {
this.intermedia ryIDCodeFieldSp ecified = value;
}
}
public string IntermediaryIde ntifier {
get {
return this.intermedia ryIdentifierFie ld;
}
set {
this.intermedia ryIdentifierFie ld = value;
}
}
}

[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="MyNames pace")]
public enum IDType_Type {

B,

C,

D,

F,

U,
}


Jul 23 '08 #4
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/P...taBinding.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...@new sgroup.nospamwr ote:
Jeff

IXmlSerializabl e 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_spa m_al...@nospam. nospamwrote in message

news:04******** *************** ***********@mic rosoft.com...
Thanks for the answer Joe.
I also found some examples of using a style sheet and doing a
transformation
(Using XslCompiledTran sform) of the original XmlDocument. *I've run atest
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 IXmlSerializabl e
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 IXmlSerializabl e 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(IsNu llable=
true) attribute to the field/property.
--
Joe Fawcett (MVP - XML)
>http://joe.fawcett.name
"j.a. harriman" <jeffrey_no_spa m_al...@nospam. nospamwrote in message
news:69******* *************** ************@mi crosoft.com...
Hi,
I have a schema that has an optional element, fieldTag4000Fie ld. *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 <fieldTag4000Fi eld/>
(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.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
* *[System.Serializ ableAttribute()]
* *[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
* *[System.Componen tModel.Designer CategoryAttribu te("code")]
* *[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
* *public partial class Request_TypeMes sageType {
* * * *private Request_TypeMes sageTypeFieldTa g4000 fieldTag4000Fie ld;
* * * *public Request_TypeMes sageTypeFieldTa g4000 FieldTag4000 {
* * * * * *get {
* * * * * * * *return this.fieldTag40 00Field;
* * * * * *}
* * * * * *set {
* * * * * * * *this.fieldTag4 000Field = value;
* * * * * *}
* * * *}
* *}
* *[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
* *[System.Serializ ableAttribute()]
* *[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
* *[System.Componen tModel.Designer CategoryAttribu te("code")]
* *[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
* *public partial class Request_TypeMes sageTypeFieldTa g4000 {
* * * *private IDType_Type intermediaryIDC odeField;
* * * *private bool intermediaryIDC odeFieldSpecifi ed;
* * * *private string intermediaryIde ntifierField;
* * * *public IDType_Type IntermediaryIDC ode {
* * * * * *get {
* * * * * * * *return this.intermedia ryIDCodeField;
* * * * * *}
* * * * * *set {
* * * * * * * *this.intermedi aryIDCodeField = value;
* * * * * *}
* * * *}
* * * *[System.Xml.Seri alization.XmlIg noreAttribute()]
* * * *public bool IntermediaryIDC odeSpecified {
* * * * * *get {
* * * * * * * *return this.intermedia ryIDCodeFieldSp ecified;
* * * * * *}
* * * * * *set {
* * * * * * * *this.intermedi aryIDCodeFieldS pecified= value;
* * * * * *}
* * * *}
* * * *public string IntermediaryIde ntifier {
* * * * * *get {
* * * * * * * *return this.intermedia ryIdentifierFie ld;
* * * * * *}
* * * * * *set {
* * * * * * * *this.intermedi aryIdentifierFi eld = value;
* * * * * *}
* * * *}
* *}
* *[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
* *[System.Serializ ableAttribute()]
* *[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="MyNames pace")]
* *public enum IDType_Type {
* * * *B,
* * * *C,
* * * *D,
* * * *F,
* * * *U,
* *}- Hide quoted text -

- Show quoted text -
Jul 30 '08 #5
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 "secondchildnod e" (count = 0):
XmlNodeList element =
doc.SelectNodes ("/parentnode/secondchildnode//*[not(node())]");

The plan is to loop through "element" and remove the nodes using the
"ParentNode.Rem oveChild" 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/P...taBinding.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...@new sgroup.nospamwr ote:
Jeff

IXmlSerializabl e 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_spa m_al...@nospam. nospamwrote in message

news:04******** *************** ***********@mic rosoft.com...
Thanks for the answer Joe.
I also found some examples of using a style sheet and doing a
transformation
(Using XslCompiledTran sform) 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 IXmlSerializabl e
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 IXmlSerializabl e 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(IsNu llable =
>true) attribute to the field/property.
>--
>Joe Fawcett (MVP - XML)
>>http://joe.fawcett.name
>"j.a. harriman" <jeffrey_no_spa m_al...@nospam. nospamwrote in message
>>news:69****** *************** *************@m icrosoft.com...
Hi,
I have a schema that has an optional element, fieldTag4000Fie ld. 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 <fieldTag4000Fi eld/>
(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.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageType {
private Request_TypeMes sageTypeFieldTa g4000 fieldTag4000Fie ld;
public Request_TypeMes sageTypeFieldTa g4000 FieldTag4000 {
get {
return this.fieldTag40 00Field;
}
set {
this.fieldTag40 00Field = value;
}
}
}
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageTypeFieldTa g4000 {
private IDType_Type intermediaryIDC odeField;
private bool intermediaryIDC odeFieldSpecifi ed;
private string intermediaryIde ntifierField;
public IDType_Type IntermediaryIDC ode {
get {
return this.intermedia ryIDCodeField;
}
set {
this.intermedia ryIDCodeField = value;
}
}
[System.Xml.Seri alization.XmlIg noreAttribute()]
public bool IntermediaryIDC odeSpecified {
get {
return this.intermedia ryIDCodeFieldSp ecified;
}
set {
this.intermedia ryIDCodeFieldSp ecified = value;
}
}
public string IntermediaryIde ntifier {
get {
return this.intermedia ryIdentifierFie ld;
}
set {
this.intermedia ryIdentifierFie ld = value;
}
}
}
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="MyNames pace")]
public enum IDType_Type {
B,
C,
D,
F,
U,
}- Hide quoted text -
- Show quoted text -

Jul 31 '08 #6

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><s econdchildnode> <b/></
secondchildnode ></parentnode>");
XmlNodeList xnl = xmlDoc.SelectNo des("//*[not(node())]");
Debug.Assert(xn l.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_spa m_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 "secondchildnod e" (count = 0):
XmlNodeList element =
doc.SelectNodes ("/parentnode/secondchildnode//*[not(node())]");

The plan is to loop through "element" and remove the nodes using the
"ParentNode.Rem oveChild" 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/P...taBinding.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...@new sgroup.nospamwr ote:
Jeff
IXmlSerializabl e 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_spa m_al...@nospam. nospamwrote in message
>news:04******* *************** ************@mi crosoft.com...
Thanks for the answer Joe.
I also found some examples of using a style sheet and doing a
transformation
(Using XslCompiledTran sform) 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 IXmlSerializabl e
that might be similar to what I need to do, but came up short. *Iwould
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 IXmlSerializabl e 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(IsNu llable =
true) attribute to the field/property.
--
Joe Fawcett (MVP - XML)
>http://joe.fawcett.name
"j.a. harriman" <jeffrey_no_spa m_al...@nospam. nospamwrote in message
>news:69******* *************** ************@mi crosoft.com...
Hi,
I have a schema that has an optional element, fieldTag4000Fie ld.*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 <fieldTag4000Fi eld/>
(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 " methodof 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.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
* *[System.Serializ ableAttribute()]
* *[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
* *[System.Componen tModel.Designer CategoryAttribu te("code")]
* *[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
* *public partial class Request_TypeMes sageType {
* * * *private Request_TypeMes sageTypeFieldTa g4000 fieldTag4000Fie ld;
* * * *public Request_TypeMes sageTypeFieldTa g4000 FieldTag4000 {
* * * * * *get {
* * * * * * * *return this.fieldTag40 00Field;
* * * * * *}
* * * * * *set {
* * * * * * * *this.fieldTag4 000Field = value;
* * * * * *}
* * * *}
* *}
* *[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
* *[System.Serializ ableAttribute()]
* *[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
* *[System.Componen tModel.Designer CategoryAttribu te("code")]
* *[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
* *public partial class Request_TypeMes sageTypeFieldTa g4000 {
* * * *private IDType_Type intermediaryIDC odeField;
* * * *private bool intermediaryIDC odeFieldSpecifi ed;
* * * *private string intermediaryIde ntifierField;
* * * *public IDType_Type IntermediaryIDC ode {
* * * * * *get {
* * * * * * * *return this.intermedia ryIDCodeField;
* * * * * *}
* * * * * *set {
* * * * * * * *this.intermedi aryIDCodeField = value;
* * * * * *}
* * * *}
* * * *[System.Xml.Seri alization.XmlIg noreAttribute()]
* * * *public bool IntermediaryIDC odeSpecified {
* * * * * *get {
* * * * * * * *return this.intermedia ryIDCodeFieldSp ecified;
* * * * * *}
* * * * * *set {
* * * * * * * *this.intermedi aryIDCodeFieldS pecified = value;
* * * * * *}
* * * *}
* * * *public string IntermediaryIde ntifier {
* * * * * *get {
* * * * * * * *return this.intermedia ryIdentifierFie ld;
* * * * * *}
* * * * * *set {
* * * * * * * *this.intermedi aryIdentifierFi eld = value;
* * * * * *}
* * * *}
* *}
* *[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
* *[System.Serializ ableAttribute()]
* *[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="MyNames pace")]
* *public enum IDType_Type {
* * * *B,
* * * *C,
* * * *D,
* * * *F,
* * * *U,
* *}- Hide quoted text -
- Show quoted text -
Aug 1 '08 #7
Building off your example, here's a respresentation of my actaul XML:
<parentnode>
<firstchildnode >
<a/>
</firstchildnode>
<secondchildnod e>
<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><s econdchildnode> <b/></
secondchildnode ></parentnode>");
XmlNodeList xnl = xmlDoc.SelectNo des("//*[not(node())]");
Debug.Assert(xn l.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_spa m_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 "secondchildnod e" (count = 0):
XmlNodeList element =
doc.SelectNodes ("/parentnode/secondchildnode//*[not(node())]");

The plan is to loop through "element" and remove the nodes using the
"ParentNode.Rem oveChild" 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/P...taBinding.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...@new sgroup.nospamwr ote:
Jeff
IXmlSerializabl e 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_spa m_al...@nospam. nospamwrote in message
news:04******** *************** ***********@mic rosoft.com...
Thanks for the answer Joe.
I also found some examples of using a style sheet and doing a
transformation
(Using XslCompiledTran sform) 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 IXmlSerializabl e
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 IXmlSerializabl e 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(IsNu llable =
>true) attribute to the field/property.
>--
>Joe Fawcett (MVP - XML)
>>http://joe.fawcett.name
>"j.a. harriman" <jeffrey_no_spa m_al...@nospam. nospamwrote in message
>>news:69****** *************** *************@m icrosoft.com...
Hi,
I have a schema that has an optional element, fieldTag4000Fie ld. 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 <fieldTag4000Fi eld/>
(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.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageType {
private Request_TypeMes sageTypeFieldTa g4000 fieldTag4000Fie ld;
public Request_TypeMes sageTypeFieldTa g4000 FieldTag4000 {
get {
return this.fieldTag40 00Field;
}
set {
this.fieldTag40 00Field = value;
}
}
}
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageTypeFieldTa g4000 {
private IDType_Type intermediaryIDC odeField;
private bool intermediaryIDC odeFieldSpecifi ed;
private string intermediaryIde ntifierField;
public IDType_Type IntermediaryIDC ode {
get {
return this.intermedia ryIDCodeField;
}
set {
this.intermedia ryIDCodeField = value;
}
}
[System.Xml.Seri alization.XmlIg noreAttribute()]
public bool IntermediaryIDC odeSpecified {
get {
return this.intermedia ryIDCodeFieldSp ecified;
}
set {
this.intermedia ryIDCodeFieldSp ecified = value;
}
}
public string IntermediaryIde ntifier {
get {
return this.intermedia ryIdentifierFie ld;
}
set {
this.intermedia ryIdentifierFie ld = value;
}
}
}
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="MyNames pace")]
public enum IDType_Type {
B,
C,
D,
F,
U,
}- Hide quoted text -
- Show quoted text -

Aug 1 '08 #8
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
XmlNamespaceMan ager) 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>
<secondchildnod e>
<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><s econdchildnode> <b/></
secondchildnode ></parentnode>");
XmlNodeList xnl = xmlDoc.SelectNo des("//*[not(node())]");
Debug.Assert(xn l.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_spa m_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 "secondchildnod e" (count = 0):
XmlNodeList element =
doc.SelectNodes ("/parentnode/secondchildnode//*[not(node())]");
>
The plan is to loop through "element" and remove the nodes using the
"ParentNode.Rem oveChild" 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/P...taBinding.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...@new sgroup.nospamwr ote:
Jeff
>
IXmlSerializabl e 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_spa m_al...@nospam. nospamwrote in message
>
>news:04******* *************** ************@mi crosoft.com...
>
Thanks for the answer Joe.
>
I also found some examples of using a style sheet and doing a
transformation
(Using XslCompiledTran sform) 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 IXmlSerializabl e
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 IXmlSerializabl e 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(IsNu llable =
true) attribute to the field/property.
>
--
>
Joe Fawcett (MVP - XML)
>
>http://joe.fawcett.name
>
"j.a. harriman" <jeffrey_no_spa m_al...@nospam. nospamwrote in message
>news:69******* *************** ************@mi crosoft.com...
Hi,
>
I have a schema that has an optional element, fieldTag4000Fie ld. 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 <fieldTag4000Fi eld/>
(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.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageType {
>
private Request_TypeMes sageTypeFieldTa g4000 fieldTag4000Fie ld;
>
public Request_TypeMes sageTypeFieldTa g4000 FieldTag4000 {
get {
return this.fieldTag40 00Field;
}
set {
this.fieldTag40 00Field = value;
}
}
}
>
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true ,
Namespace="MyNa mespace")]
public partial class Request_TypeMes sageTypeFieldTa g4000 {
>
private IDType_Type intermediaryIDC odeField;
>
private bool intermediaryIDC odeFieldSpecifi ed;
>
private string intermediaryIde ntifierField;
>
public IDType_Type IntermediaryIDC ode {
get {
return this.intermedia ryIDCodeField;
}
set {
this.intermedia ryIDCodeField = value;
}
}
>
[System.Xml.Seri alization.XmlIg noreAttribute()]
public bool IntermediaryIDC odeSpecified {
get {
return this.intermedia ryIDCodeFieldSp ecified;
}
set {
this.intermedia ryIDCodeFieldSp ecified = value;
}
}
>
public string IntermediaryIde ntifier {
get {
return this.intermedia ryIdentifierFie ld;
}
set {
this.intermedia ryIdentifierFie ld = value;
}
}
}
>
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd",
"2.0.50727. 42")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="MyNames pace")]
public enum IDType_Type {
>
B,
>
C,
>
D,
>
F,
>
U,
}- Hide quoted text -
>
- Show quoted text -
Aug 1 '08 #9
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
XmlNamespaceMan ager) 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 XmlNamespaceMan ager and bind prefixes to the
namespace URIs to use the prefixes in your XPath expressions to qualify
element or attribute names. The XmlNamespaceMan ager is then passed as
the second argument to the SelectNodes or SelectSingleNod e calls.
If you need more concrete help then show us the relevant XML.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 1 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1633
by: Zion Zadik | last post by:
Dear all, I have a set of c# data classes which i need to fill their data from xml files. serialization looks to be the best way to accomplish this task. Since the data classes are compiled and i don't have control on the xml structure, I tried using the xmlAttributeOverrides class, to instruct the serializer. I was able to override the attributes for the root element, but I'm having problems understanding how to deserialize arrays.
8
3571
by: Harris Boyce | last post by:
Hello, I'm trying to use the FOR XML EXPLICIT clause with SQL Server to deserialize data from my database into a strongly-typed collection object that I will use throughout my application. I initially tested my design by building a collection in code and then serializing it to/from an XML file, which worked fine. However, I have hit a brick wall trying to restore the data from SQL Server. I originally had my collection and object
0
3030
by: keith bannister via .NET 247 | last post by:
(Type your message here) -------------------------------- From: keith bannister Hi, I'm new to .net (as of last week) but here goes. I want to serialize/deserialize a file the conforms to an XML schema (xsd).
5
7288
by: Keith Bannister | last post by:
I'm new to .net so here goes. I'm tying to deserialize a class that is associated with an XML schema. I created the C# class with xsd.exe as below: xsd.exe /c /n:somenamespace properties.xsd this creates properties.cs
4
15767
by: Alexis | last post by:
Hello, Is there a way of telling the XmlSerializer to ignore all namespaces when deserializing. I'm using XmlAttributeOverrides, but I have to do it for every class the OutputObject usses. Is there an "ApplyToAll" kind of feature? I also tried the defaultNamespace, but it didn't work.
2
4063
by: Vivek | last post by:
In an application which uses an XML file, I wish to use XmlSchemaValidator class to validate this file against the XSD file.. In the example of msdn, ( http://msdn2.microsoft.com/en-us/library/system.xml.schema.xmlschemavalidator(VS.80).aspx ) , before initialising the XmlSchemaValidator, XmlSerializer is initialised. I saw that if there is a node or attribute which is not valid (to xml schema), the method XmlSerializer.Deserialize()...
0
1448
by: Vivek | last post by:
In an application which uses an XML file, I wish to use XmlSchemaValidator class to validate this file against the XSD file.. In the example of msdn, ( http://msdn2.microsoft.com/en-us/library/system.xml.schema.xmlschemavalidator(VS.80).aspx ) , before initialising the XmlSchemaValidator, XmlSerializer is initialised. I saw that if there is a node or attribute which is not valid (to xml schema), the method XmlSerializer.Deserialize()...
1
5124
by: Yewen Tang | last post by:
I have a schema file datamodel.xsd, element "properties" is declared as a type of "baseProperty". The schema file also defines "derivedProperty" is a derived type of "baseProperty". <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:myns="uri:myschema" targetNamespace="uri:myschema" elementFormDefault="qualified" version="1.0"> <xs:complexType name="derivedProperty">
0
812
by: conniehl | last post by:
Hello, I am trying to use XmlSerializer to deserialize an xml file and then use a loop to access the content. With the help of xsd.exe, a serializer class is generated and I am able to use that to deserialize the following xml: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <layercatalog> <category jcode="aaa"> <layerList> <layer> <trackNumber>1</trackNumber>
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.