generate xml at runtime

Discussion in 'XML' started by Zombie, Oct 18, 2004.

  1. Zombie

    Zombie Guest

    hello,
    I am generating an XML document at run time.
    I have been able to create the root element and the elements below it
    but I am not able to add attributes to elements. Can anyone please
    send a snippet on how to do this?

    Thanks.

    The sample code I am using is:

    ----------------------------------------------------
    HRESULT hr;
    IXMLDOMDocument2Ptr pXMLDoc;
    IXMLDOMNodePtr pNode;
    IXMLDOMProcessingInstructionPtr pi;

    hr = pXMLDoc.CreateInstance("Msxml2.DOMDocument.4.0");
    pi = pXMLDoc->createProcessingInstruction("xml", "version=\"1.0\"");
    pXMLDoc->appendChild(pi);

    pNode = pXMLDoc->createNode("1", "root", "");
    pXMLDoc->appendChild(pNode);

    pNode = pXMLDoc->createNode("1", "element1", "");
    pXMLDoc->documentElement->appendChild(pNode);

    ------------------------------------------------------
    Zombie, Oct 18, 2004
    #1
    1. Advertising

  2. Zombie

    Andy Dingley Guest

    On 18 Oct 2004 03:24:53 -0700, (Zombie) wrote:

    >I have been able to create the root element and the elements below it
    >but I am not able to add attributes to elements.


    Try the .setAttribute() method
    Andy Dingley, Oct 18, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Weng Tianxiang
    Replies:
    5
    Views:
    1,298
    Christophe
    Feb 16, 2006
  2. Lucia
    Replies:
    7
    Views:
    7,625
    vinny503
    Aug 19, 2011
  3. Replies:
    3
    Views:
    396
    red floyd
    Apr 7, 2006
  4. Harlan Messinger
    Replies:
    2
    Views:
    2,279
    John Bell
    Mar 28, 2010
  5. Matt
    Replies:
    3
    Views:
    325
    Bob Barrows [MVP]
    Apr 23, 2004
Loading...

Share This Page