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
Arne Vajhøj - 26 Dec 2007 03:52 GMT
> My XML knowledge is extreemly limited but learning not quite fast enough!
>
[quoted text clipped - 8 lines]
> How do I access the value of "Address ID=" from within C# code using the
> XMLDocument?
Try:
doc.SelectSingleNode("//ZipCodeLookupResponse/Address/@ID").Value
Arne
Mr. Arnold - 26 Dec 2007 03:56 GMT
> My XML knowledge is extreemly limited but learning not quite fast enough!
>
[quoted text clipped - 12 lines]
> 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. :)
newscorrespondent@charter.net - 26 Dec 2007 04:06 GMT
I think I got the answer. The Address ID is an attribute of a node not the
document which I was originally checking.
Yasir Zaheer - 26 Dec 2007 10:18 GMT
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.
On Dec 26, 9:06 am, newscorrespond...@charter.net wrote:
> I think I got the answer. The Address ID is an attribute of a node not the
> document which I was originally checking.
BELÁK Miloš - 27 Dec 2007 09:06 GMT
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š
Arne Vajhøj - 28 Dec 2007 01:57 GMT
> Prajem pekný deň.
> Potreboval by som vygenerovať funkciou Random
[quoted text clipped - 3 lines]
> 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