Extracting innertext and attribute using XmlSerializer

  • Thread starter Thread starter kishore
  • Start date Start date
K

kishore

Hi
I have a file similar to below


<filter>
<param id="xx">This is test</param>
<param id="yy">This is another test </param>
</filter>

I created classes as below

[XmlRoot("filter")]
public class Filter
{
[XmlElement("param", typeof(Param))]
Param [] params;
}

public class Param
{
[XmlAttribute("id")]
public string id;
}


All this is working fine. But I am not sure how to get the inner texts
from the Param element. How can I get it through serialization?

Please help.

Thanks in advance.
 
Xml serialisation is only going serialise the state of an object to xml it
does not provide any mechanism to recurse the xml you will have to use an
xml query tool for that.

Also I believe you should be using the XmlArrayAttribute on your array:

[XmlRoot("filter")]
public class Filter
{
[XmlArray(ElementName = "Params")
Param [] params;
}

[XmlElement("Param")]
public class Param
{
[XmlAttribute("id")]
public string id;
}

HTH

Ollie Riches
 
Hi Ollie,
Thanks for the reply. Even if i could get hold of the inner text, i
could extract the value on my own. I don't see a way to get it out?
I believe when deserialized (convert from xml file to object), it
should be reading even the innertext also right?
How do i get hold of it?

Thanks
Kishore


Xml serialisation is only going serialise the state of an object to xml it
does not provide any mechanism to recurse the xml you will have to use an
xml query tool for that.

Also I believe you should be using the XmlArrayAttribute on your array:

[XmlRoot("filter")]
public class Filter
{
[XmlArray(ElementName = "Params")
Param [] params;

}

[XmlElement("Param")]
public class Param
{
[XmlAttribute("id")]
public string id;

}

HTH

Ollie Riches




Hi
I have a file similar to below
<filter>
<param id="xx">This is test</param>
<param id="yy">This is another test </param>
</filter>
I created classes as below
[XmlRoot("filter")]
public class Filter
{
[XmlElement("param", typeof(Param))]
Param [] params;
}
public class Param
{
[XmlAttribute("id")]
public string id;
}
All this is working fine. But I am not sure how to get the inner texts
from the Param element. How can I get it through serialization?
Please help.
Thanks in advance.- Hide quoted text -

- Show quoted text -
 
declare a Text field on Param:

public class Param {
[XmlAttribute("id")]
public string id;

[XmlText]
public string text;
}

HTH,

Sam
 
Thanks Samuel. That was what i was looking for.

Kishore

declare a Text field on Param:

public class Param {
[XmlAttribute("id")]
public string id;

[XmlText]
public string text;

}

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

Hi
I have a file similar to below
<filter>
<param id="xx">This is test</param>
<param id="yy">This is another test </param>
</filter>
I created classes as below
[XmlRoot("filter")]
public class Filter
{
[XmlElement("param", typeof(Param))]
Param [] params;
}
public class Param
{
[XmlAttribute("id")]
public string id;
}
All this is working fine. But I am not sure how to get the inner texts
from the Param element. How can I get it through serialization?
Please help.
Thanks in advance.- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top