473,770 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pull single property out of xml file?

I am saving a class by giving it the "Serializab le" attribute, and calling
Serialize. Is there a way that I can pull the value of an individual member
of the class, out of the resulting xml file, without constructing a new
instance of the class deserializing the file into it? In this case, I just
need the value of a string member, and don't want to construct the entire
class to get it.
Nov 16 '05 #1
4 1360
Dave,

The xml that the XmlSerializer generates for a particular type should be
pretty consistent. I would say to take a look at the output that the type
that you are serializing generates, and then construct an XPath query that
you can use to get the value.

For primitive value types, this should be fine, but for propreties that
return class instances, you might have no other option than to run the
XmlSerializer on the whole thing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dave" <dp*@nospam.eli assen.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
I am saving a class by giving it the "Serializab le" attribute, and calling
Serialize. Is there a way that I can pull the value of an individual
member
of the class, out of the resulting xml file, without constructing a new
instance of the class deserializing the file into it? In this case, I
just
need the value of a string member, and don't want to construct the entire
class to get it.

Nov 16 '05 #2
Nicholas:

Thanks for the reply, but I guess I forgot to mention that I'm new to this
stuff. "Xpath query"? How do I do that? Maybe a simple example would make
my question more clear:

Suppose I have a class as follows:

[Serializable] public class foo {
public string member1;
public string member2;
};

And, I serialize it as follows:

....
foo xx = new foo();
xx.member1 = "test value";
xx.member2 = "test value2";
FileStream fs = new FileStream("tes t.xml", FileMode.Create );
SoapFormatter s = new SoapFormatter() ;
s.AssemblyForma t =
System.Runtime. Serialization.F ormatters.Forma tterAssemblySty le.Simple;
s.Serialize(fs, foo);
fs.Close();

So, now I have a file, "test.xml", and I want to pull out the value of
"member1", without deserializing the file into a new instance of foo. How
do I do that?

- Dave

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:eQ******** ******@TK2MSFTN GP14.phx.gbl...
Dave,

The xml that the XmlSerializer generates for a particular type should be pretty consistent. I would say to take a look at the output that the type
that you are serializing generates, and then construct an XPath query that
you can use to get the value.

For primitive value types, this should be fine, but for propreties that return class instances, you might have no other option than to run the
XmlSerializer on the whole thing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dave" <dp*@nospam.eli assen.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
I am saving a class by giving it the "Serializab le" attribute, and calling Serialize. Is there a way that I can pull the value of an individual
member
of the class, out of the resulting xml file, without constructing a new
instance of the class deserializing the file into it? In this case, I
just
need the value of a string member, and don't want to construct the entire class to get it.


Nov 16 '05 #3
Dave,

Can you post test.xml? Then, we can see the structure, and tell you how
to get the value.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dave" <dp*@nospam.eli assen.com> wrote in message
news:uv******** ******@TK2MSFTN GP14.phx.gbl...
Nicholas:

Thanks for the reply, but I guess I forgot to mention that I'm new to this
stuff. "Xpath query"? How do I do that? Maybe a simple example would
make
my question more clear:

Suppose I have a class as follows:

[Serializable] public class foo {
public string member1;
public string member2;
};

And, I serialize it as follows:

...
foo xx = new foo();
xx.member1 = "test value";
xx.member2 = "test value2";
FileStream fs = new FileStream("tes t.xml", FileMode.Create );
SoapFormatter s = new SoapFormatter() ;
s.AssemblyForma t =
System.Runtime. Serialization.F ormatters.Forma tterAssemblySty le.Simple;
s.Serialize(fs, foo);
fs.Close();

So, now I have a file, "test.xml", and I want to pull out the value of
"member1", without deserializing the file into a new instance of foo. How
do I do that?

- Dave

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in
message news:eQ******** ******@TK2MSFTN GP14.phx.gbl...
Dave,

The xml that the XmlSerializer generates for a particular type should

be
pretty consistent. I would say to take a look at the output that the
type
that you are serializing generates, and then construct an XPath query
that
you can use to get the value.

For primitive value types, this should be fine, but for propreties

that
return class instances, you might have no other option than to run the
XmlSerializer on the whole thing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dave" <dp*@nospam.eli assen.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
>I am saving a class by giving it the "Serializab le" attribute, and calling > Serialize. Is there a way that I can pull the value of an individual
> member
> of the class, out of the resulting xml file, without constructing a new
> instance of the class deserializing the file into it? In this case, I
> just
> need the value of a string member, and don't want to construct the entire > class to get it.
>
>



Nov 16 '05 #4
Ok. My actual class is more complex, but if you can explain how to do
it with this test code, I think I can figure out the rest. Here's the xml
file produced:

<SOAP-ENV:Envelope xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap .org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap .org/soap/envelope/"
xmlns:clr="http ://schemas.microso ft.com/soap/encoding/clr/1.0"
SOAP-ENV:encodingSty le="http://schemas.xmlsoap .org/soap/encoding/">
<SOAP-ENV:Body>
<a1:foo id="ref-1"
xmlns:a1="http://schemas.microso ft.com/clr/nsassem/XMLTest2/XMLTest2">
<member1 id="ref-3">test value</member1>
<member2 id="ref-4">test value2</member2>
</a1:foo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Here's the code I used to produce the above:

using System;
using System.IO;
using System.Runtime. Serialization.F ormatters.Soap;
namespace XMLTest
{
[Serializable] public class foo {
public string member1;
public string member2;
static void Main(string[] args)
{
foo xx = new foo();
xx.member1 = "test value";
xx.member2 = "test value2";
FileStream fs = new FileStream(@"c: \test.xml",
FileMode.Create );
SoapFormatter s = new SoapFormatter() ;
s.AssemblyForma t =

System.Runtime. Serialization.F ormatters.Forma tterAssemblySty le.Simple;
s.Serialize(fs, xx);
fs.Close();
}
};
}

- Dave
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in message news:<uz******* *******@TK2MSFT NGP11.phx.gbl>. ..
Dave,

Can you post test.xml? Then, we can see the structure, and tell you how to get the value.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dave" <dp*@nospam.eli assen.com> wrote in message
news:uv******** ******@TK2MSFTN GP14.phx.gbl...
Nicholas:

Thanks for the reply, but I guess I forgot to mention that I'm new to this stuff. "Xpath query"? How do I do that? Maybe a simple example would make
my question more clear:

Suppose I have a class as follows:

[Serializable] public class foo {
public string member1;
public string member2;
};

And, I serialize it as follows:

...
foo xx = new foo();
xx.member1 = "test value";
xx.member2 = "test value2";
FileStream fs = new FileStream("tes t.xml", FileMode.Create );
SoapFormatter s = new SoapFormatter() ;
s.AssemblyForma t =
System.Runtime. Serialization.F ormatters.Forma tterAssemblySty le.Simple; s.Serialize(fs, foo);
fs.Close();

So, now I have a file, "test.xml", and I want to pull out the value of "member1", without deserializing the file into a new instance of foo. How do I do that?

- Dave

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:eQ******** ******@TK2MSFTN GP14.phx.gbl...
Dave,

The xml that the XmlSerializer generates for a particular type should
be
pretty consistent. I would say to take a look at the output that
the type
that you are serializing generates, and then construct an XPath query that
you can use to get the value.

For primitive value types, this should be fine, but for propreties that
return class instances, you might have no other option than to run
the XmlSerializer on the whole thing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dave" <dp*@nospam.eli assen.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
>I am saving a class by giving it the "Serializab le" attribute, and

calling
> Serialize. Is there a way that I can pull the value of an individual > member
> of the class, out of the resulting xml file, without constructing a new > instance of the class deserializing the file into it? In this case, I > just
> need the value of a string member, and don't want to construct

the entire
> class to get it.
>
>



Nov 16 '05 #5

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

Similar topics

5
4777
by: Glenn Mulno | last post by:
Hi, I am trying to create a report page for several teams. Each team runs the same reports but the reports use different values. For a while this was getting insane everytime I updated the queries I had to change them in many places. Then I started using server side includes to keep me from changing some items in multiple places. There is still some double (quadruple) updating going on though when I make
2
6953
by: Jeremy Dillinger | last post by:
I have a program setup to pull data from a database. My database table has things such as (category, Item, price, etc.) In my program I want to have multiple list boxes that will have a pull down list of different categories. The category is stored as a number and the item is stored as a string. Also once the item is picked from the list I would also like to extract the price corresponding to the chosen item. This program will be to...
6
8641
by: Sakharam Phapale | last post by:
Hi All, How to capture Mouse Single click and mouse double click event on Commnad Button. I am doing as follows. Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp If e.Clicks = 1 Then
2
1078
by: Alex Maghen | last post by:
I don't seem to be able to do anything to change the border style of my standard pull-down list controls on a page. I've messed with the Style property, the Border-Style property, everything. Nothing seems to have any effect. Any idea why? Is this even possible? All I want is to change it from Beveled to single line border.
2
8156
by: Jonathan Kacprowicz | last post by:
I am trying to create a build process using MSBuild that will build my multiple projects all with the same AssemblyVersion and AssemblyFileVersion. I have tried using the AssemblyInfo task from the community tasks projects (http://msbuildtasks.tigris.org/) and the AssemblyInfoTask from the MSBuild blog (http://www.gotdotnet.com/codegallery/codegallery.aspx?id=93d23e13-c653-4815-9e79-16107919f93e). My scenario is this: I have several...
2
2498
by: TPK | last post by:
I have an HTML document with Javascript where I have a portion of the page contents, a series of questions, being pulled from a XML file. When the page dynamically builds all the questions and selection choices are listed top down in the order they appear in the XML file. Here is an example of the XML formatting: <question type="single_answer">The text of a question. <answer correct="no">A. Answer One <user_feedback>Incorrect...
4
1941
by: sparks | last post by:
We have a new project here, one that I have never tried maybe its easy I don't know yet. We have people that have records dating back over 5 yrs on a sql server. We have to build an access 2003 database for data entry of the people then pull data from the sql server to fill in data for these records. that sounds good....except to start I need record # and date....no problems there.
10
3521
by: Neil | last post by:
Using the MS Rich Textbox Control 6.0 in Access 2000, I need to concatenate several RTB controls into a single RTF file. Sometimes two strings will be side-by-side; other times they need to be separated by a hard return. For example, say I have the following 4 RTB controls in my form: RTB1 = "abcd" RTB2 = "efgh" RTB3 = "ijkl" RTB4 = "mnop"
5
1721
by: cover | last post by:
I'm trying to populate the pulldown menus of a single input form through queries from a single table. The three columns are 'name', 'type', and 'status'. The name table runs to approx row 23, the type, to row 8, and status, row 9. . I'm using the following code to populate the form pulldown menus:: <?php $query = "SELECT DISTINCT status FROM $table"; $result = mysql_query($query);
0
9432
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
10232
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
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...
1
10008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7420
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
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
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
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
2
3578
muto222
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.