1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

writing attribute using libxml

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

  1. gamodg

    gamodg New Member

    Joined:
    Mar 22, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Mar 27, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Mar 22, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Thank you very much for the help.
     

Share This Page