How do programmers normally write XML files?

R

Ramon F Herrera

(newbie alert)

I am developing a C++ application, and decided that the best format to
save files is in this newfangled :) XML thing.

I already had a similar problem in Java and found a healthy number of
implementations. I also found several which are written in C++, like
this one, which seems very attractive:

http://xerces.apache.org/xerces-c/

The question I have is about writing XML files. I am under the
impression that most of the hard work is the reading and the parsing.
I can't find a simple example in which there is writing. Is writing so
easy (compared with parsing, that is) that people just roll their own
and don't use XML libraries?

What I am really looking for is a library/sample code (Xerces is my
top choice right now) that writes a simple, tutorial type XML file. I
just want to make sure that the library is a fit for my problem.

TIA!

-RFH
 
P

Peter Flynn

Ramon said:
(newbie alert)

I am developing a C++ application, and decided that the best format to
save files is in this newfangled :) XML thing.

Hardly newfangled nowadays...it's been over a decade, and its
predecessor for another decade before that.
I already had a similar problem in Java and found a healthy number of
implementations. I also found several which are written in C++, like
this one, which seems very attractive:

http://xerces.apache.org/xerces-c/

The question I have is about writing XML files.

It depends what you mean by *writing*.

A) If you are using XML for marking up data for storage or transfer
between applications, that's usually done under program control,
by library calls, so *you* don't actually write anything with your
fingers.

B) On the other hand if you're talking about authoring text, like
documentation, articles, books, etc, then you need a decent XML
editor if you want to do it in XML. There are almost no usable ones
except for technical authoring.
I am under the
impression that most of the hard work is the reading and the parsing.

By the look of it you're talking about (A). Xerces is a parser, just one
(critical) component of an XML toolchain. There are many others. In
isolation, a parser won't do very much for you except parse your
incoming and outgoing XML (checking it for syntax: well-formedness).

You will also need an XML editor, at least to open the [test] file
you write so that you can see that they've been done right.
I can't find a simple example in which there is writing. Is writing so
easy (compared with parsing, that is) that people just roll their own
and don't use XML libraries?

All the people I know who do this stuff use XML libraries. They exist
for every language AFAIK (even COBOL :)
What I am really looking for is a library/sample code (Xerces is my
top choice right now) that writes a simple, tutorial type XML file. I
just want to make sure that the library is a fit for my problem.

If we knew what your problem was, we might be able to recommend something.

///Peter
 
R

Ramon F Herrera

Ramon said:
(newbie alert)
I am developing a C++ application, and decided that the best format to
save files is in this newfangled :) XML thing.

Hardly newfangled nowadays...it's been over a decade, and its
predecessor for another decade before that.
I already had a similar problem in Java and found a healthy number of
implementations. I also found several which are written in C++, like
this one, which seems very attractive:

The question I have is about writing XML files.

It depends what you mean by *writing*.

A) If you are using XML for marking up data for storage or transfer
between applications, that's usually done under program control,
by library calls, so *you* don't actually write anything with your
fingers.

B) On the other hand if you're talking about authoring text, like
documentation, articles, books, etc, then you need a decent XML
editor if you want to do it in XML. There are almost no usable ones
except for technical authoring.
I am under the
impression that most of the hard work is the reading and the parsing.

By the look of it you're talking about (A). Xerces is a parser, just one
(critical) component of an XML toolchain. There are many others. In
isolation, a parser won't do very much for you except parse your
incoming and outgoing XML (checking it for syntax: well-formedness).

You will also need an XML editor, at least to open the [test] file
you write so that you can see that they've been done right.
I can't find a simple example in which there is writing. Is writing so
easy (compared with parsing, that is) that people just roll their own
and don't use XML libraries?

All the people I know who do this stuff use XML libraries. They exist
for every language AFAIK (even COBOL :)
What I am really looking for is a library/sample code (Xerces is my
top choice right now) that writes a simple, tutorial type XML file. I
just want to make sure that the library is a fit for my problem.

If we knew what your problem was, we might be able to recommend something.

///Peter


Thanks for your answer, Peter. I should have clarified that my
concerns are those of a programmer. I am designing my own file format,
which is pretty straightforward: a handful different objects, each one
with a set of attributes which vary a little from one class of object
to the next.

I downloaded Xerces-C and have playing with the samples; I debating
with myself if it is worth all the trouble, just to write a simple
file and place the tags in the proper places.

OTOH, and needless to say, I will *definitely* need the parsing
functions of the library in order to read files, later on.

-RFH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top