Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML add attribute

Status
Not open for further replies.

Sniipe

Programmer
Oct 9, 2006
115
IE
Hello I have an element like the following element
<part qty="1" description="Christmas Tree" Price="10eur"/>

I can access the part by

Code:
XmlNodeList xmlNodLst =	(XMLDoc.GetElementsByTagName("part");
if(xmlNodLst !=	null)
{
   for (int i = 0; i < xmlNodLst.Count; i++)
   {
      XmlNode xmlnod = xmlNodLst[i];
   }
}
How would I add another attribute onto that?
I was thinking it was something like
xmlnod.attribute.add ... but there is no .add

Any ideas?

Thanks
 
so, basically I have to create an attribute; its not just a case of using a string
Code:
string ns = root.GetNamespaceOfPrefix("bk");
    XmlNode attr = doc.CreateNode(XmlNodeType.Attribute, "genre", ns);
    attr.Value = "novel";

Thanks again B00gyeMan, I was going down this messy route:
Code:
for	(int i = 0;	i <	xmlNodLst.Count; i++)
				{
					XmlNode	xmlnod = xmlNodLst[i];		
					string temp = xmlnod.OuterXml.ToString();
						
					//Calculate the line price
					string selectedPrice = null;
					string qty = null;
                    int selPos = temp.LastIndexOf("selectedPrice");
					int selPosEnd = temp.
					
					
					//Add the new attribute
					
					int position = temp.LastIndexOf("\"");
					temp = temp.Insert(position + 1," " + "linePrice=");
				}
Hopefully ur code link will help me some. I'll have a try now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top