generate xml at runtime

Z

Zombie

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);

------------------------------------------------------
 
A

Andy Dingley

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top