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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top