Hi. I am trying to read the value of an attribute, in an XML file. Its a very simple xml file.
<?xml version="1.0"?>
<product type="Tile">
<name>3ba01</name>
<pattern>rojo</pattern>
</product>
I can get both name and pattern. I cannot for the life of me, get the product type attribute. I am using c#. The following is what i am doing
///////////////////////////////////////////
xmlstr = Server.MapPath("XML/products.xml");
XmlTextReader reader = new XmlTextReader(xmlstr);
while(reader.Read())
{
if((reader.Name == "product"))
{
reader.MoveToAttribute("type");
{ reader.Attributes.Value.ToString());
}
}
if((reader.Name == "name") && (reader.NodeType == XmlNodeType.Element))
{
XML_name = reader.ReadElementString("name").ToString();
///////////////////////////////////////
etc.........
The above is just pseudocode by the way.
}
Thankyou.
What do you guys use to grab the value of an attribute?
<?xml version="1.0"?>
<product type="Tile">
<name>3ba01</name>
<pattern>rojo</pattern>
</product>
I can get both name and pattern. I cannot for the life of me, get the product type attribute. I am using c#. The following is what i am doing
///////////////////////////////////////////
xmlstr = Server.MapPath("XML/products.xml");
XmlTextReader reader = new XmlTextReader(xmlstr);
while(reader.Read())
{
if((reader.Name == "product"))
{
reader.MoveToAttribute("type");
{ reader.Attributes.Value.ToString());
}
}
if((reader.Name == "name") && (reader.NodeType == XmlNodeType.Element))
{
XML_name = reader.ReadElementString("name").ToString();
///////////////////////////////////////
etc.........
The above is just pseudocode by the way.
}
Thankyou.
What do you guys use to grab the value of an attribute?