xml node data to C# object

C

cronusf

I have an xml file where I only need to extract data from certain
nodes. I am using XPathNavigator to find the nodes I want. My
question is, once I have the node I want, is there an easy way to
convert it to a C# object. For example, if I have the node:

<Point3>
<x>54.7</x>
<y>55.9</y>
<z>0.005</z>
</Point3>

and a corresponding Point3 structure in C#, is there a way I could do
something like:

Point3 p = (Point3)xpathnavigator.Value();

I tried using ValueAs:

Point3 p = (Point3)xpathnavigator.ValueAs(typeof(Point3));

but it threw an exception. Obviously I could move to the lower level
and use the property ValueAsDouble, but I would like to read in
structs at a time, if possible, rather than hitting every data member.
 
T

Tom Dacon

I have an xml file where I only need to extract data from certain
nodes. I am using XPathNavigator to find the nodes I want. My
question is, once I have the node I want, is there an easy way to
convert it to a C# object. For example, if I have the node:

<Point3>
<x>54.7</x>
<y>55.9</y>
<z>0.005</z>
</Point3>

and a corresponding Point3 structure in C#, is there a way I could do
something like:

Point3 p = (Point3)xpathnavigator.Value();

I tried using ValueAs:

Point3 p = (Point3)xpathnavigator.ValueAs(typeof(Point3));

but it threw an exception. Obviously I could move to the lower level
and use the property ValueAsDouble, but I would like to read in
structs at a time, if possible, rather than hitting every data member.

I'd suggest that you add a constructor to your Point3 structure that takes
an XmlNode as its argument. In the constructor you'd get the child nodes and
set the property values from their text parsed as floating-point variables.

Tom Dacon
Dacon Software Consulting
 
V

Vitalii Alks

Good luck with this services <a href="http://englishpapers.org/">English paper</a>



cronus wrote:

xml node data to C# object
10-Jan-09

I have an xml file where I only need to extract data from certai
nodes. I am using XPathNavigator to find the nodes I want. M
question is, once I have the node I want, is there an easy way t
convert it to a C# object. For example, if I have the node

<Point3
<x>54.7</x
<y>55.9</y
<z>0.005</z
</Point3

and a corresponding Point3 structure in C#, is there a way I could d
something like

Point3 p = (Point3)xpathnavigator.Value()

I tried using ValueAs

Point3 p = (Point3)xpathnavigator.ValueAs(typeof(Point3))

but it threw an exception. Obviously I could move to the lower leve
and use the property ValueAsDouble, but I would like to read i
structs at a time, if possible, rather than hitting every data member.

Previous Posts In This Thread:

Re: xml node data to C# object

I'd suggest that you add a constructor to your Point3 structure that takes
an XmlNode as its argument. In the constructor you'd get the child nodes and
set the property values from their text parsed as floating-point variables

Tom Daco
Dacon Software Consulting

xml node data to C# object
I have an xml file where I only need to extract data from certai
nodes. I am using XPathNavigator to find the nodes I want. M
question is, once I have the node I want, is there an easy way t
convert it to a C# object. For example, if I have the node

<Point3
<x>54.7</x
<y>55.9</y
<z>0.005</z
</Point3

and a corresponding Point3 structure in C#, is there a way I could d
something like

Point3 p = (Point3)xpathnavigator.Value()

I tried using ValueAs

Point3 p = (Point3)xpathnavigator.ValueAs(typeof(Point3))

but it threw an exception. Obviously I could move to the lower leve
and use the property ValueAsDouble, but I would like to read i
structs at a time, if possible, rather than hitting every data member.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Sending SMTP email from within BizTalk Orchestration
http://www.eggheadcafe.com/tutorial...f-1716445b26bc/sending-smtp-email-from-w.aspx
 
V

Vitalii Alks

werwerwerwe



cronus wrote:

xml node data to C# object
10-Jan-09

I have an xml file where I only need to extract data from certai
nodes. I am using XPathNavigator to find the nodes I want. M
question is, once I have the node I want, is there an easy way t
convert it to a C# object. For example, if I have the node

<Point3
<x>54.7</x
<y>55.9</y
<z>0.005</z
</Point3

and a corresponding Point3 structure in C#, is there a way I could d
something like

Point3 p = (Point3)xpathnavigator.Value()

I tried using ValueAs

Point3 p = (Point3)xpathnavigator.ValueAs(typeof(Point3))

but it threw an exception. Obviously I could move to the lower leve
and use the property ValueAsDouble, but I would like to read i
structs at a time, if possible, rather than hitting every data member.

Previous Posts In This Thread:

Re: xml node data to C# object

I'd suggest that you add a constructor to your Point3 structure that takes
an XmlNode as its argument. In the constructor you'd get the child nodes and
set the property values from their text parsed as floating-point variables

Tom Daco
Dacon Software Consulting

xml node data to C# object
I have an xml file where I only need to extract data from certai
nodes. I am using XPathNavigator to find the nodes I want. M
question is, once I have the node I want, is there an easy way t
convert it to a C# object. For example, if I have the node

<Point3
<x>54.7</x
<y>55.9</y
<z>0.005</z
</Point3

and a corresponding Point3 structure in C#, is there a way I could d
something like

Point3 p = (Point3)xpathnavigator.Value()

I tried using ValueAs

Point3 p = (Point3)xpathnavigator.ValueAs(typeof(Point3))

but it threw an exception. Obviously I could move to the lower leve
and use the property ValueAsDouble, but I would like to read i
structs at a time, if possible, rather than hitting every data member.

Post
Good luck with this services <a href="http://englishpapers.org/">English paper</a>


Submitted via EggHeadCafe - Software Developer Portal of Choice
Measuring SharePoint Page Rendering
http://www.eggheadcafe.com/tutorial...1-9d5f236c2be5/measuring-sharepoint-page.aspx
 
V

Vitalii Alks

wqwdqwdqwdqwdqwd wqd qwd qwd



cronus wrote:

xml node data to C# object
10-Jan-09

I have an xml file where I only need to extract data from certai
nodes. I am using XPathNavigator to find the nodes I want. M
question is, once I have the node I want, is there an easy way t
convert it to a C# object. For example, if I have the node

<Point3
<x>54.7</x
<y>55.9</y
<z>0.005</z
</Point3

and a corresponding Point3 structure in C#, is there a way I could d
something like

Point3 p = (Point3)xpathnavigator.Value()

I tried using ValueAs

Point3 p = (Point3)xpathnavigator.ValueAs(typeof(Point3))

but it threw an exception. Obviously I could move to the lower leve
and use the property ValueAsDouble, but I would like to read i
structs at a time, if possible, rather than hitting every data member.

Previous Posts In This Thread:

Re: xml node data to C# object

I'd suggest that you add a constructor to your Point3 structure that takes
an XmlNode as its argument. In the constructor you'd get the child nodes and
set the property values from their text parsed as floating-point variables

Tom Daco
Dacon Software Consulting

xml node data to C# object
I have an xml file where I only need to extract data from certai
nodes. I am using XPathNavigator to find the nodes I want. M
question is, once I have the node I want, is there an easy way t
convert it to a C# object. For example, if I have the node

<Point3
<x>54.7</x
<y>55.9</y
<z>0.005</z
</Point3

and a corresponding Point3 structure in C#, is there a way I could d
something like

Point3 p = (Point3)xpathnavigator.Value()

I tried using ValueAs

Point3 p = (Point3)xpathnavigator.ValueAs(typeof(Point3))

but it threw an exception. Obviously I could move to the lower leve
and use the property ValueAsDouble, but I would like to read i
structs at a time, if possible, rather than hitting every data member.

Post
Good luck with this services <a href="http://englishpapers.org/">English paper</a>

er
werwerwerwe


Submitted via EggHeadCafe - Software Developer Portal of Choice
Join Lists with LINQ - SharePoint 2010
http://www.eggheadcafe.com/tutorial...6e-7d3fb7d38eca/join-lists-with-linq--sh.aspx
 

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

Top