How to capture attribute in xml ?

  • Thread starter Thread starter C# newbie
  • Start date Start date
C

C# newbie

Hi, This is part of an xml file:

<Page PageID="Page12" PageName="AgeGender" StyleUsage="" PageLayout="Flow"
Duration="0" AutoSubmit="false" ProtectImages="false" SwapOnMouseOver="true"
NextPage="P2" Order="1" HideByCondition="false">
<Params>
bluh
bluh
bluh
bluh

How can I read the page name ? is there any method for this purpose or I
should real the whole text and tokenize the PageName form the text ?
any suggestions ?

thx
 
No you don't have to parse and tokenize text. instead you have to use
the XML parser.

Read a tutorial or book on XML processing with C# and you will find out
that there are easy api available to read the value of attributes of an
element.

regards,
Abhishek.
 
Try this :
doc = new XmlDocument();
doc.Load(yourFile);
String pageName =
doc.SelectSingleNode("Page").Attributes["PageName"].Value.ToString();

Hope that helps.
jmd
 
Thanks...

Abhishek Srivastava said:
No you don't have to parse and tokenize text. instead you have to use
the XML parser.

Read a tutorial or book on XML processing with C# and you will find out
that there are easy api available to read the value of attributes of an
element.

regards,
Abhishek.
 
Back
Top