473,473 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Extracting innertext and attribute using XmlSerializer

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
4 5865
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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cognizance | last post by:
Hi gang, I'm an ASP developer by trade, but I've had to create client side scripts with JavaScript many times in the past. Simple things, like validating form elements and such. Now I've been...
0
by: jr | last post by:
Hello, I have got a schema file "myschema.xsd" from my customer for which I must create xml files. I used xsd.exe to create a class for the schema. I fill an object for that class with data...
9
by: AA | last post by:
Hello, I need to extract an element from a xml document something like this <myXml> <Header> <Name/> <LastName/> <Age/> </Head> <Body> <Properties>
2
by: Paul Duncan | last post by:
Hi. The question is: How do I set the value of PageElement to the innertext 'Hello World' in my xml when I use XMLSerializer? My source xml is: <book> <page number="1">Hello World</page>...
4
by: Justine | last post by:
Hi All, I would like to know where & when exactly we would have a need for attributes. A realistic example. Thanz in Advance, Justine
1
by: Bob Rock | last post by:
Hello, I have a web method that serializes a class that includes among its public fields a System.Object field to which, at runtime, I assign instances of various different classes. When...
1
by: chrisfost | last post by:
Is it possible by using attributes to serialize a <List<List<Point>> property to output as shown below? Current Output <PolyPolyline> <ArrayOfPoint> <Point> <X>5</X> <Y>5</Y>
2
by: chris_j_adams | last post by:
Hi, I'm slowly discovering the world of JavaScript, so I'm not sure I'm attacking this problem in the right manner, thus if I'm in the wrong newsgroup, my apologies. What I'm trying to do is...
10
by: Henrik Dahl | last post by:
Hello! I have an xml schema which has a date typed attribute. I have used xsd.exe to create a class library for XmlSerializer. The result of XmlSerializer.Serialize(...) should be passed as the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.