Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Printing XML st...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 45400 of 48002
Post > Topic >>

Printing XML string With XML tags

by "Joah Senegal" <bloker@[EMAIL PROTECTED] > Apr 24, 2008 at 12:24 AM

Hello all,

I;m a beginner with XML. All I want is to print the XML string with tags.
In 
the following example, there is function called: xmlNodeGetString. This 
function is getting a char*  back. The result of this function is the XML 
elements of the list without tags (Jaap, Kees, Kris). at the end of this 
example a function xmlSaveFormatFile writes a XML file. looking like:

<?xml version="1.0"?>
<LinkedList><Element>Jaap</Element><Element>Kees</Element><Element>Kris</Element></LinkedList>

So what I want to do is writing the lines normally writting in the file on

the screen using printf. So if I do a printf I need to get something like:

<?xml version="1.0"?>
<LinkedList>
<Element>Jaap</Element>
<Element>Kees</Element>
<Element>Kris</Element>
</LinkedList>

I;ve searched for xmlfunctions for this, but I'm failing to find the right

one. Does anyone know how to get a output like above? I want do something 
like this:

        char *fname ;
        for ( ; p ; p = p->next ) {
                 if (p->type == XML_ELEMENT_NODE) {
                        fname = (char *)SOMEXMLFUNCTION(.........)   }
                        printf (fname);
        }

In the place om SOMEXMLFUNCTION should me a xmlfunction that spits out 
things like this:

<Element>Jaap</Element>





------example----
#include <iostream>

#include <libxml/parser.h>

using namespace std ;

int main() {

        xmlNode *xNode ;
        xmlDocPtr doc  ;

        doc = xmlNewDoc(BAD_CAST "1.0");

        xNode = xmlNewNode(NULL, BAD_CAST "LinkedList");
        xmlDocSetRootElement(doc, xNode);

        xmlNewChild(xNode,NULL,(xmlChar *)"Element", (xmlChar *)"Jaap" ) ;
        xmlNewChild(xNode,NULL,(xmlChar *)"Element", (xmlChar *)"Kees" ) ;
        xmlNewChild(xNode,NULL,(xmlChar *)"Element", (xmlChar *)"Kris" ) ;


        xmlNode * p = xNode->children ;

        char *fname ;
        for ( ; p ; p = p->next ) {
                 if (p->type == XML_ELEMENT_NODE) {
                        fname = (char *)xmlNodeListGetString(p->doc, 
p->xmlChildrenNode, 1);
                 }

                cout << fname  << endl ;
        }

        xmlSaveFormatFile ("LinkedList.xml", doc, 0);
        xmlFreeDoc(doc);


}
 




 3 Posts in Topic:
Printing XML string With XML tags
"Joah Senegal"   2008-04-24 00:24:35 
Re: Printing XML string With XML tags
Christopher <cpisz@[EM  2008-04-23 15:41:35 
Re: Printing XML string With XML tags
Paavo Helde <nobody@[E  2008-04-24 13:17:32 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 14:19:01 CDT 2008.