By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,780 Members | 1,520 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,780 IT Pros & Developers. It's quick & easy.

Extracting innertext and attribute using XmlSerializer

P: n/a
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.

Feb 6 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"kishore" <vk******@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.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.

Feb 6 '07 #2

P: n/a
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
On Feb 6, 2:49 am, "Ollie Riches" <ollie_ric...@hotmail.comwrote:
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

"kishore" <vkbul...@gmail.comwrote in message

news:11**********************@j27g2000cwj.googlegr oups.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 -

Feb 6 '07 #3

P: n/a

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.
On 5 Feb 2007 22:05:16 -0800, "kishore" <vk******@gmail.comwrote:
>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.
Feb 6 '07 #4

P: n/a
Thanks Samuel. That was what i was looking for.

Kishore

On Feb 6, 11:43 am, Samuel R. Neff <samueln...@nomail.comwrote:
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.

On 5 Feb 2007 22:05:16 -0800, "kishore" <vkbul...@gmail.comwrote:
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 -

Feb 6 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.