writing attribute using libxml

gamodg's Avatar, Join Date: Mar 2009
Light Poster
I want to write an xml tag like:

<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 !!!
alwaysLearning's Avatar, Join Date: Mar 2009
Go4Expert Member

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:

                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*/
I havent run this code, but it should work fine.
for more information see this:

gamodg's Avatar, Join Date: Mar 2009
Light Poster
Thank you very much for the help.