473,385 Members | 1,325 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,385 software developers and data experts.

Getting a value out of XML

Howdy,

I'm new to ASP.Net 2.0 and XML in general. I've used XML documents as
datasets plenty but never had to find a specific value in one before. Below
is a sample XML document I'm working with and my code I'm using to pull the
specific email address from the XML document. Is this the best way of doing
this? Is there a better, faster procedure?

<?xml version="1.0" encoding="utf-8" ?>

<root>

<email ad************@delphi-ts.com name="David Lozzi"></email>

<email ad************@delphi-ts.com name="David J. Lozzi"></email>

</root>
Dim xr As New XmlTextReader(Server.MapPath("~/xml/addresses.xml"))

xr.ReadToDescendant("root")

Do While xr.Read

If xr.HasAttributes Then

If xr.GetAttribute("name").ToString = "David Lozzi" Then

Response.Write(xr.GetAttribute("address"))

End If

End If

Loop


Thanks,

David Lozzi

Aug 15 '06 #1
6 1075
Hi,

David Lozzi wrote:
Howdy,

I'm new to ASP.Net 2.0 and XML in general. I've used XML documents as
datasets plenty but never had to find a specific value in one before. Below
is a sample XML document I'm working with and my code I'm using to pull the
specific email address from the XML document. Is this the best way of doing
this? Is there a better, faster procedure?

<?xml version="1.0" encoding="utf-8" ?>

<root>

<email ad************@delphi-ts.com name="David Lozzi"></email>

<email ad************@delphi-ts.com name="David J. Lozzi"></email>

</root>
<snip>

Can you modify the XML code? If yes, you could add an ID to your email
tag, the load the document and use GetElementById instead of the loop.

Note that your XML is not well formed: attributes should be enclosed in
"", and empty tags should be put in the form <... /instead of <...></...>

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 16 '06 #2
David,
You can also use XmlDocument to modify the document and do whatever
you want to do.
Patrick

"David Lozzi" <dl****@nospam.nospamwrote in message
news:eQ**************@TK2MSFTNGP06.phx.gbl...
Howdy,

I'm new to ASP.Net 2.0 and XML in general. I've used XML documents as
datasets plenty but never had to find a specific value in one before.
Below is a sample XML document I'm working with and my code I'm using to
pull the specific email address from the XML document. Is this the best
way of doing this? Is there a better, faster procedure?

<?xml version="1.0" encoding="utf-8" ?>

<root>

<email ad************@delphi-ts.com name="David Lozzi"></email>

<email ad************@delphi-ts.com name="David J. Lozzi"></email>

</root>
Dim xr As New XmlTextReader(Server.MapPath("~/xml/addresses.xml"))

xr.ReadToDescendant("root")

Do While xr.Read

If xr.HasAttributes Then

If xr.GetAttribute("name").ToString = "David Lozzi" Then

Response.Write(xr.GetAttribute("address"))

End If

End If

Loop


Thanks,

David Lozzi

Aug 16 '06 #3
Can I have a little more explanation? I tried using the XMLDocument but
couldn't figure out how.

Thanks,
David
"Patrick.O.Ige" <na********@hotmail.comwrote in message
news:OT*************@TK2MSFTNGP05.phx.gbl...
David,
You can also use XmlDocument to modify the document and do whatever
you want to do.
Patrick

"David Lozzi" <dl****@nospam.nospamwrote in message
news:eQ**************@TK2MSFTNGP06.phx.gbl...
>Howdy,

I'm new to ASP.Net 2.0 and XML in general. I've used XML documents as
datasets plenty but never had to find a specific value in one before.
Below is a sample XML document I'm working with and my code I'm using to
pull the specific email address from the XML document. Is this the best
way of doing this? Is there a better, faster procedure?

<?xml version="1.0" encoding="utf-8" ?>

<root>

<email ad************@delphi-ts.com name="David Lozzi"></email>

<email ad************@delphi-ts.com name="David J. Lozzi"></email>

</root>
Dim xr As New XmlTextReader(Server.MapPath("~/xml/addresses.xml"))

xr.ReadToDescendant("root")

Do While xr.Read

If xr.HasAttributes Then

If xr.GetAttribute("name").ToString = "David Lozzi" Then

Response.Write(xr.GetAttribute("address"))

End If

End If

Loop


Thanks,

David Lozzi


Aug 16 '06 #4
Thanks for the tips. I can change the name to ID, or does it have to be an
integer?

Thanks,

David Lozzi
"Laurent Bugnion" <ga*********@bluewin.chwrote in message
news:el**************@TK2MSFTNGP06.phx.gbl...
Hi,

David Lozzi wrote:
>Howdy,

I'm new to ASP.Net 2.0 and XML in general. I've used XML documents as
datasets plenty but never had to find a specific value in one before.
Below is a sample XML document I'm working with and my code I'm using to
pull the specific email address from the XML document. Is this the best
way of doing this? Is there a better, faster procedure?

<?xml version="1.0" encoding="utf-8" ?>

<root>

<email ad************@delphi-ts.com name="David Lozzi"></email>

<email ad************@delphi-ts.com name="David J. Lozzi"></email>

</root>

<snip>

Can you modify the XML code? If yes, you could add an ID to your email
tag, the load the document and use GetElementById instead of the loop.

Note that your XML is not well formed: attributes should be enclosed in
"", and empty tags should be put in the form <... /instead of
<...></...>

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

Aug 16 '06 #5
Hi,

David Lozzi wrote:
Thanks for the tips. I can change the name to ID, or does it have to be an
integer?

Thanks,

David Lozzi
The ID can be any string, as long as it is unique throughout the document.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 16 '06 #6
http://www.asp.net/QuickStart/howto/...mentEvent.aspx
hope that helps
Patrick

"David Lozzi" <dl****@nospam.nospamwrote in message
news:ue**************@TK2MSFTNGP03.phx.gbl...
Can I have a little more explanation? I tried using the XMLDocument but
couldn't figure out how.

Thanks,
David
"Patrick.O.Ige" <na********@hotmail.comwrote in message
news:OT*************@TK2MSFTNGP05.phx.gbl...
>David,
You can also use XmlDocument to modify the document and do whatever
you want to do.
Patrick

"David Lozzi" <dl****@nospam.nospamwrote in message
news:eQ**************@TK2MSFTNGP06.phx.gbl...
>>Howdy,

I'm new to ASP.Net 2.0 and XML in general. I've used XML documents as
datasets plenty but never had to find a specific value in one before.
Below is a sample XML document I'm working with and my code I'm using to
pull the specific email address from the XML document. Is this the best
way of doing this? Is there a better, faster procedure?

<?xml version="1.0" encoding="utf-8" ?>

<root>

<email ad************@delphi-ts.com name="David Lozzi"></email>

<email ad************@delphi-ts.com name="David J. Lozzi"></email>

</root>
Dim xr As New XmlTextReader(Server.MapPath("~/xml/addresses.xml"))

xr.ReadToDescendant("root")

Do While xr.Read

If xr.HasAttributes Then

If xr.GetAttribute("name").ToString = "David Lozzi" Then

Response.Write(xr.GetAttribute("address"))

End If

End If

Loop


Thanks,

David Lozzi



Aug 17 '06 #7

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

Similar topics

2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
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...
5
by: Manjiri | last post by:
Hello Everybody... Here i have the program which prints how many number of times the element appears in the array.... The code is as follows... #include<iostream.h> class Count
4
by: bushi | last post by:
hi ! i have following code to display some text on a web form,after getting it from database. <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate>...
1
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
10
by: Mike | last post by:
I have code that is doing some updating to a record. Its getting the ID to update from the Grid. I'm passing an INT to my method to update the record. My code is working though I'm still getting an...
0
by: buntyindia | last post by:
Hi, I have a very strange problem with my application. I have developed it using Struts. I have a TextBox With Some fixed value in it and on Submit iam passing it to another page. <html:form...
13
by: jcato77 | last post by:
I am having trouble figuring out my code and was hoping someone could point me in the right direction. Below is my code what I need to due is create a method to add and display the value of the...
9
vikas251074
by: vikas251074 | last post by:
I am not getting date value in spite of my good effort. This code was working in my last office where I work. Now I am trying to work at my home pc. but not getting date value. Any can help me why...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.