using System.Net and System.XML Question

N

newscorrespondent

My XML knowledge is extreemly limited but learning not quite fast enough!

I am getting some XML back from the USPS web service as a string

<?xml version="1.0"?>
<ZipCodeLookupResponse><Address ID="0"><Address2>6406 IVY
LN</Address2><City>GREENBELT</City><State>MD</State><Zip5>20770</Zip5><Zip4>1440</Zip4></Address></ZipCodeLookupResponse>


I create a System.Xml.XmlDocument and then load the string.

How do I access the value of "Address ID=" from within C# code using the
XMLDocument?

From one of my books I think this is an attribute but when I check it tells
me there are no attributes in the document.


Thanks
Tom Groszko
 
A

Arne Vajhøj

My XML knowledge is extreemly limited but learning not quite fast enough!

I am getting some XML back from the USPS web service as a string

<?xml version="1.0"?>
<ZipCodeLookupResponse><Address ID="0"><Address2>6406 IVY
LN</Address2><City>GREENBELT</City><State>MD</State><Zip5>20770</Zip5><Zip4>1440</Zip4></Address></ZipCodeLookupResponse>

I create a System.Xml.XmlDocument and then load the string.

How do I access the value of "Address ID=" from within C# code using the
XMLDocument?

Try:

doc.SelectSingleNode("//ZipCodeLookupResponse/Address/@ID").Value

Arne
 
M

Mr. Arnold

My XML knowledge is extreemly limited but learning not quite fast enough!

I am getting some XML back from the USPS web service as a string

<?xml version="1.0"?>
<ZipCodeLookupResponse><Address ID="0"><Address2>6406 IVY
LN</Address2><City>GREENBELT</City><State>MD</State><Zip5>20770</Zip5><Zip4>1440</Zip4></Address></ZipCodeLookupResponse>


I create a System.Xml.XmlDocument and then load the string.

How do I access the value of "Address ID=" from within C# code using the
XMLDocument?

From one of my books I think this is an attribute but when I check it
tells
me there are no attributes in the document.

It's in VB, but you can do the same thing in C#.

http://developer.yahoo.com/dotnet/howto-xml_vb.html

This may help you too in the future.

http://support.softartisans.com/kbview_675.aspx

I feel your pain. I am working on a C# Web service that is to make contact
with a 3rd party Web service to send/receive XML Documents.

I am learning more about XML than I ever cared to know. :)
 
N

newscorrespondent

I think I got the answer. The Address ID is an attribute of a node not the
document which I was originally checking.
 
Y

Yasir Zaheer

Actually, the attribute is not "Address ID", it is only "ID"
associated with the node "Address". you can check the values like :
xmlDocument.SelectSingleNode("//ZipCodeLookupResponse/
Address").Attributes["ID"].Value. and this will give you the value of
that attribute.

Regards,
Yasir Zaheer.
 
B

BELÃK MiloÅ¡

Prajem pekný deň.
Potreboval by som vygenerovať funkciou Random
Äíslo do nejakej premennej. V praxi by som chcel
vytvoriÅ¥ nejaký príklad pre výpoÄet.
Nech som hľadal ako hľadal, ale niÄ som rozumné nenaÅ¡iel.
Nemáte nejaký slušný Netlink, kde by to bolo možné doštudovať?
Dik za pomoc.
S pozdravom Miloš
 
A

Arne Vajhøj

BELÃK MiloÅ¡ said:
Prajem pekný deň.
Potreboval by som vygenerovať funkciou Random
Äíslo do nejakej premennej. V praxi by som chcel
vytvoriÅ¥ nejaký príklad pre výpoÄet.
Nech som hľadal ako hľadal, ale niÄ som rozumné nenaÅ¡iel.
Nemáte nejaký slušný Netlink, kde by to bolo možné doštudovať?
Dik za pomoc.

You may get more responses if you try post in english.

Arne
 

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