Adding a XML Attribute for an Exiting Node

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter

    #1

    Adding a XML Attribute for an Exiting Node

    Hi,
    If I use the following code, there is a attribute.
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<i tem id='301'>Pink Ale Beer</item>");

    If I code the 2nd line as below:
    doc.LoadXml("<i tem>Pink Ale Beer</item>");
    My question is how to add the attribute after that.
    Please advice. Thanks.
    Peter




  • Randy Charles Morin

    #2
    Re: Adding a XML Attribute for an Exiting Node

    Sample
    static void Main(string[] args)
    {
    System.Xml.XmlD ocument doc = new System.Xml.XmlD ocument();
    doc.LoadXml("<i tem>Pink Ale Beer</item>");
    doc.DocumentEle ment.SetAttribu te("id", "301");
    System.Console. WriteLine(doc.D ocumentElement. OuterXml);
    }

    Hope this helps,

    Randy
    Learn and build with modern AI: clear explainers, hands-on tools, and guided paths, plus fast developer references. Everything runs in your browser,…


    "Peter" <anonymous@disc ussions.microso ft.com> wrote in message news:<f79b01c3b ddf$8f26d7b0$a6 01280a@phx.gbl> ...[color=blue]
    > Hi,
    > If I use the following code, there is a attribute.
    > XmlDocument doc = new XmlDocument();
    > doc.LoadXml("<i tem id='301'>Pink Ale Beer</item>");
    >
    > If I code the 2nd line as below:
    > doc.LoadXml("<i tem>Pink Ale Beer</item>");
    > My question is how to add the attribute after that.
    > Please advice. Thanks.
    > Peter[/color]

    Comment

    Working...