1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

writing attribute using libxml

Discussion in 'C' started by gamodg, Apr 1, 2009.

  1. gamodg

    gamodg New Member

    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 !!!
     
  2. alwaysLearning

    alwaysLearning New Member

    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/
     
  3. gamodg

    gamodg New Member

    Thank you very much for the help.
     

Share This Page