473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Printing XML string With XML tags

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);
}

Jun 27 '08 #1
2 3662
On Apr 23, 5:24 pm, "Joah Senegal" <blo...@hva.nlwrote:
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);

}
There is no standard C++ XML library. You will have to use a third
party library or write your own. Luckily there are several. One
popular one is Xerces. I however, would prefer to write my own. The
details of which could fit in a book and are OT here.

You could easily create a string aroudn another string to wrap <and
</around it, but that is only one form and element can take. what if
it has children? what if it has attributes? etc etc. You get into a
complicated tree structure and lots of decision making.
Jun 27 '08 #2
Christopher <cp***@austin.rr.comwrote in
news:66**********************************@t54g2000 hsg.googlegroups.com:
On Apr 23, 5:24 pm, "Joah Senegal" <blo...@hva.nlwrote:
>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:
[...]
>>
#include <libxml/parser.h>
This appears to be a question about libxml, which is most probably off-
topic here.
There is no standard C++ XML library. You will have to use a third
party library or write your own. Luckily there are several. One
popular one is Xerces. I however, would prefer to write my own. The
details of which could fit in a book and are OT here.
Indeed, Xerces seems to be an overkill in this case. I am not familiar with
libxml; for studying purposes I would recommend the TinyXML library -
small, readable, usable and quite C++.

HTH
Paavo
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been...
2
by: Michael G | last post by:
I have an online application that generates some data. Currently the data is being displayed in browsers using basic html. Each set of data generates a separate report. I want to send these reports...
5
by: Patrick De Ridder | last post by:
How can I turn what I want to print 90 degrees using the logic below? Please tell me the code with which to make the modification. Many thanks, Patrick. using System.ComponentModel; using...
3
by: Ahmad Abu-Raddad | last post by:
Hey Guys, Does anyone knows of a way to print HTML source directly to the printer (Server Side)?. I tried the PrintDocument class and the e.Graphics.DrawString and e.Graphics.DrawImage() but...
4
by: Rob T | last post by:
I have a small VB program that has a printing module...very simple....and works great. However, If I try to print to a generic printer, I get the following error: "The data area passed to a...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
3
by: John Peterson | last post by:
Hello all! I'm at my wits end trying to search for what I assumed to be a relatively straightforward task. I have a Web application written in C#, and I have a button on the form that I want to...
15
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! Does anyone know how can I do barcode printing? First of all, I know I have to write a client executable, but how do I communicate with the thermal printer? Using software the...
11
by: S N | last post by:
how to print apostrophe character ' and double quote " in asp using vbscript. my code using response.write replaces " character with inverted question mark. please help
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.