Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   writing attribute using libxml (http://www.go4expert.com/forums/writing-attribute-using-libxml-t16761/)

gamodg 1Apr2009 23:42

writing attribute using libxml
 
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 !!!

alwaysLearning 2Apr2009 02:59

Re: writing attribute using libxml
 
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/

gamodg 2Apr2009 08:22

Re: writing attribute using libxml
 
Thank you very much for the help.


All times are GMT +5.5. The time now is 10:45.