writing attribute using libxml

Light Poster
1Apr2009,23:42   #1
gamodg's Avatar
I want to write an xml tag like:

Code:
<type readonly=1 pos=3>textbox</type>

I am using xmlTextWriterWriteFormatElement to write type tag with value as text box and then calling xmlTextWriterWriteAttribute to insert attributes but it is giving an error.
Please help me !!!
Go4Expert Member
2Apr2009,02:59   #2
alwaysLearning's Avatar
Hi,

Writing attribute to an element is quite easy, i didnt use ur functions before but these are the function which you can try to create an element and add atribute to it:

Code:
                doc = xmlNewDoc(BAD_CAST "1.0");
	root_node = xmlNewNode(NULL, BAD_CAST "NameOfRootNode");

	xmlDocSetRootElement(doc, root_node);

               /*Lets add the type tag in your xml*/
               node = xmlNewChild(root_node, NULL, BAD_CAST "type", "textbox");

              /*Now adding the properties*/
             xmlNewProp(node, BAD_CAST "readonly",BAD_CAST ("1") );
             xmlNewProp(node, BAD_CAST "pos",BAD_CAST ("3") );


            /*Now dumping the document in a charecter buf*/
             xmlDocDumpFormatMemory(doc,&buf,&size,0);
I havent run this code, but it should work fine.
for more information see this:

http://www.xmlsoft.org/tutorial/
Light Poster
2Apr2009,08:22   #3
gamodg's Avatar
Thank you very much for the help.