473,326 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Get some value from XML file

Hello.
I have XML file like this:

==========================================
<?xml version="1.0" encoding="utf-8" ?>
<Language>
<English>
<Captions>
<Name>Some caption</Name>
</Captions>
<Messages>
<Name>Some message</Name>
</Messages>
</English>
</Language>
==========================================

I want to read from this XML file "Some message" which is on
Language\English\Messages section.
How can I do this?
Can anybody show me some example?

Thank you.
Nov 16 '05 #1
3 28873
Hi David,

using System.Xml

Construct xml document using

XmlDocument doc = new XmlDocument;

Load document

doc.Load(file);

Now adress the text node

XmlNode node = doc.SelectSingleNode("Language/English/Messages/Name/text()");

then read the value into a string

string foo = node.Value;

Use XPath expressions in the selectSingleNode function!

Regards Jesper,Denmark

"David" wrote:
Hello.
I have XML file like this:

==========================================
<?xml version="1.0" encoding="utf-8" ?>
<Language>
<English>
<Captions>
<Name>Some caption</Name>
</Captions>
<Messages>
<Name>Some message</Name>
</Messages>
</English>
</Language>
==========================================

I want to read from this XML file "Some message" which is on
Language\English\Messages section.
How can I do this?
Can anybody show me some example?

Thank you.

Nov 16 '05 #2
Than you very much for helping.
I have one more question please:
=======================================
<?xml version="1.0" encoding="utf-8" ?>
<Languages>
<Language Lnag="English" />
<Captions>
<Name>Some English caption</Name>
</Captions>
<Language>
<Language Lnag="German" />
<Captions>
<Name>Some German caption</Name>
</Captions>
<Language>
</Languages>
=======================================
Can you show me please how can I get "Some English caption"?

Thank you?
"Jesper" <Je****@discussions.microsoft.com> wrote in message
news:2C**********************************@microsof t.com...
Hi David,

using System.Xml

Construct xml document using

XmlDocument doc = new XmlDocument;

Load document

doc.Load(file);

Now adress the text node

XmlNode node =
doc.SelectSingleNode("Language/English/Messages/Name/text()");

then read the value into a string

string foo = node.Value;

Use XPath expressions in the selectSingleNode function!

Regards Jesper,Denmark

"David" wrote:
Hello.
I have XML file like this:

==========================================
<?xml version="1.0" encoding="utf-8" ?>
<Language>
<English>
<Captions>
<Name>Some caption</Name>
</Captions>
<Messages>
<Name>Some message</Name>
</Messages>
</English>
</Language>
==========================================

I want to read from this XML file "Some message" which is on
Language\English\Messages section.
How can I do this?
Can anybody show me some example?

Thank you.

Nov 16 '05 #3
Yep!

XmlNode node =
doc.SelectSingleNode("Languages/Language[@Lnag='English']/Captions/Name/text()");

string foo = node.Value;

the [] brackets serve as filters setting a condition. @ indicate an attribute.

best regards Jesper
"David" wrote:
Than you very much for helping.
I have one more question please:
=======================================
<?xml version="1.0" encoding="utf-8" ?>
<Languages>
<Language Lnag="English" />
<Captions>
<Name>Some English caption</Name>
</Captions>
<Language>
<Language Lnag="German" />
<Captions>
<Name>Some German caption</Name>
</Captions>
<Language>
</Languages>
=======================================
Can you show me please how can I get "Some English caption"?

Thank you?
"Jesper" <Je****@discussions.microsoft.com> wrote in message
news:2C**********************************@microsof t.com...
Hi David,

using System.Xml

Construct xml document using

XmlDocument doc = new XmlDocument;

Load document

doc.Load(file);

Now adress the text node

XmlNode node =
doc.SelectSingleNode("Language/English/Messages/Name/text()");

then read the value into a string

string foo = node.Value;

Use XPath expressions in the selectSingleNode function!

Regards Jesper,Denmark

"David" wrote:
Hello.
I have XML file like this:

==========================================
<?xml version="1.0" encoding="utf-8" ?>
<Language>
<English>
<Captions>
<Name>Some caption</Name>
</Captions>
<Messages>
<Name>Some message</Name>
</Messages>
</English>
</Language>
==========================================

I want to read from this XML file "Some message" which is on
Language\English\Messages section.
How can I do this?
Can anybody show me some example?

Thank you.


Nov 16 '05 #4

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

Similar topics

3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
7
by: matthew_carver | last post by:
Hello, I have an ASP page that loops through a SQL Server 2000 table, then downloads an Excel sheet the users can save, etc. Works fine, except, I see that in one particular "comments" field the...
2
by: Matt | last post by:
If I do the following, the browse text box still cannot see C:/hello world/test.txt. <input type="file" name="fileName" value="C:/hello world/test.txt" size=80> Any ideas? and workarounds...
5
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: ...
6
by: melanieab | last post by:
Hi, Easy question. It seems to me that I'm following the examples correctly, but apparently I'm not. I'm trying to retrieve the data from a row called "row" and a column called "File". This is...
2
by: Bilal | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all...
1
Fary4u
by: Fary4u | last post by:
Hi Guys i'm trying to upload a file, i've tried 3 different methods but still not work out i don't know how to over come this problem hidden file value, multiple form or popup uploading. 1-...
0
by: Fredrik Lundh | last post by:
maurizio wrote: What kind of file is it? Did you pick numpy because you want to do matrix operations (beyond just finding a maximum value), or was it just the first thing you stumbled upon...
1
by: maurizio | last post by:
thank you for your answer actually i've to do some statistics (maximum,minimum,mean,standard deviation,....) of a file of data in which each column is a particular type of data. (the file is a tab...
0
by: grego9 | last post by:
I have a bit of visual basic code in an excel spreadsheet that I need some help with. I am attempting to search a file called TO Cancellations2.xls for counterparty names and for each counterparty...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.