Connecting Tech Pros Worldwide Help | Site Map

Attributes in XML

Newbie
 
Join Date: Jun 2006
Posts: 1
#1: Jun 12 '06
Hi

I have the following xml tag I am trying to get info from

<text x="300" y="400" font-size="5" font-family="Arial" >230</text>

I can get the >230< out using the code

Expand|Select|Wrap|Line Numbers
  1. //Load xml document
  2.         XmlDataDocument doc = new XmlDataDocument();
  3.         doc.Load(Server.MapPath("myfile.xml"));
  4.  
  5.         //Find the text tag
  6.         XmlNodeList results = doc.GetElementsByTagName("text");
  7.  
  8.         //Display the results
  9.         foreach (XmlNode result in results)
  10.         {
  11.             lblXml.Text += result.FirstChild.Value + "<br>";
  12.         }
I also need to get the x and y out, how do i do this, is it something to do with XPath, Attributes?

If so how?

Regards

Richard
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,156
#2: Jun 13 '06

re: Attributes in XML


It might help if you told us what language you are using, x, y, font-size and font-family are all attributes of the text tag. XPath would be used to locate the text tag in the XML document.

If this is part of the MS .Net framework then try blXml.Attributes,
Reply