You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by appleGuy <al...@gmail.com> on 2006/12/15 01:15:57 UTC

Starting To Use Xerces

Hi,

This could be quite a long thread, so please bear with me.
Ok ive got Xerces installed & its compiling the example correctly.

Now im totally new to XML let alone this parser. Ive contructed the
following xml file. I need the file to contain data that can be parsed &
values loaded into predefined variables within my application.. Firstly I
suppose I need to know if my XML file is ok: (the example uses place holders
so author in a real file would be a persons name)

<?xml version="1.0" encoding="ISO-8859-1"?>
<loopcardprj>
	<_prjsetup>
		<title>untitled</title>
		<author>author</author>
		<subject>subject</subject>
		<card>subject</card>
	</_prjsetup>
	<_questions>"What Is 5 x 3?","What Is 5 x 5?","What Is 5 x 5?"</_questions>
	<_answers>"15","25","10"</_answers>
	<_comment>This is an example of a file layout for the LoopCard Software By
Alex Curtis</_comment>	
</loopcardprj>

(IF OK): I need to know how to use the parser to parse this file & dump the
data into the correct variables. I read that DOMBuilder was the class to
use???

Please If you could help, im really new to this XML / Parsing Business...


Many Thanks
-Alex
-- 
View this message in context: http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7884089
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Starting To Use Xerces

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi Alex,

appleGuy <al...@gmail.com> writes:

> This Code Synthesis XSD  Looks like just what i Need but I just Need
> clarification.
>
> Ive got a project Class, it has variables that I need the XML Data to fill.
> There are also containers (lists) that need to be filled. All in the same
> class.
>
> Would I use C++/Tree or C++/Parser? I need something really easy to use as
> time is short..

The C++/Tree mapping is really easy to use and it supports both reading
and writing of XML. The only potential drawback, in your case, is that
it also provides you with the in-memory representation so you may have
to copy the data to your own data structures. Even then, I think, it
is many times easier to use than SAX or DOM. Here is a five minute
goide to the C++/Tree mapping:

http://codesynthesis.com/projects/xsd/documentation/cxx/tree/quick-guide/


The C++/Parser mapping is somewhat similar in the idea to SAX. It
provides you with events that you can use to build up your own in-
memory representation. It is also somewhat more difficult to use
compared to C++/Tree so if the time is short I suggest you go with
the latter. Here is a five minute goide to the C++/Parser mapping:

http://codesynthesis.com/projects/xsd/documentation/cxx/parser/quick-guide/


If you have any further questions about CodeSynthesis XSD or need
help, feel free to post to xsd-users@codesyntesis.com mailing list
(no registration required).


hth,
-boris


-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding


RE: Starting To Use Xerces

Posted by appleGuy <al...@gmail.com>.
Ok, this seems to be going nowhere (internal fustration...no offence meant)

Im ignoring XSD....At the end of the day, I just need a quick SIMPLE way of
looking trough an XML File & pushing the XML File data into pre-defined
variable & containers...


-Alex


Jesse Pelton wrote:
> 
> I haven't used XSD myself.  One of its authors subscribes to this list
> and may respond, but I'd try one of the lists specific to the product,
> listed at http://codesynthesis.com/support/. 
> 
> -----Original Message-----
> From: appleGuy [mailto:alx.curtis@gmail.com] 
> Sent: Friday, December 15, 2006 8:56 AM
> To: c-users@xerces.apache.org
> Subject: RE: Starting To Use Xerces
> 
> 
> Hi,
> 
> This Code Synthesis XSD  Looks like just what i Need but I just Need
> clarification.
> 
> Ive got a project Class, it has variables that I need the XML Data to
> fill.
> There are also containers (lists) that need to be filled. All in the
> same
> class.
> 
> Would I use C++/Tree or C++/Parser? I need something really easy to use
> as
> time is short..
> 
> After further reading im not too bothard about using seperate methods of
> reading & writing XML docs.
> 
> Cheers
> Alex
> 
> 
> Jesse Pelton wrote:
>> 
>> You don't necessarily have to use the same method for reading
> documents
>> that you use for generating them.  SAX is a great interface for
> building
>> up data structures from a document.  It's fast, flexible, and
> efficient.
>> DOM parsing also has its uses, of course, but it tends to be more
>> cumbersome, and uses much more memory.  DOM shines in document
> creation,
>> however.  So I tend to use SAX for parsing and DOM for generating
>> documents, and I suspect that I'm in good company.  It makes a lot of
>> sense when you're using XML to represent data that already has an
>> in-memory representation, that is, when XML is just a serialization
>> format for your data.
>> 
>> Nonetheless, it sounds like the DOM does what you need.
>> 
>> You might want to look at the sample apps (DOMPrint, for instance) to
>> get a sense of how to use the DOM APIs.  Also consider XML data
> binding
>> tools such as Code Synthesis XSD
>> (http://codesynthesis.com/products/xsd/), which is based on Xerces.
>> 
>> -----Original Message-----
>> From: appleGuy [mailto:alx.curtis@gmail.com] 
>> Sent: Friday, December 15, 2006 8:29 AM
>> To: c-users@xerces.apache.org
>> Subject: Re: Starting To Use Xerces
>> 
>> 
>> Hi,
>> 
>> Ok I made the changes to the XML file.
>> I think im going to use Dom, i read that it allows saving & creating
> XML
>> files. I need to use this eventually & because I have a short
> timeframe
>> I
>> just want to get used to one method. IIs this Ok, will Dom Fufil my
>> needs?
>> 
>> Also How would I start to impliment the Dom (for reading files)...
> dont
>> see
>> a constructor anywhere in the docs...Is it createDOMBuilder ??
>> 
>> Cheers
>> Alex
>> 
>> 
>> Alberto Massari wrote:
>>> 
>>> At 16.15 14/12/2006 -0800, appleGuy wrote:
>>> 
>>>>Hi,
>>>>
>>>>This could be quite a long thread, so please bear with me.
>>>>Ok ive got Xerces installed & its compiling the example correctly.
>>>>
>>>>Now im totally new to XML let alone this parser. Ive contructed the
>>>>following xml file. I need the file to contain data that can be
> parsed
>> &
>>>>values loaded into predefined variables within my application..
>> Firstly I
>>>>suppose I need to know if my XML file is ok: (the example uses place
>> holders
>>>>so author in a real file would be a persons name)
>>>>
>>>><?xml version="1.0" encoding="ISO-8859-1"?>
>>>><loopcardprj>
>>>>         <_prjsetup>
>>>>                 <title>untitled</title>
>>>>                 <author>author</author>
>>>>                 <subject>subject</subject>
>>>>                 <card>subject</card>
>>>>         </_prjsetup>
>>>>         <_questions>"What Is 5 x 3?","What Is 5 x 5?","What Is 5 x 
>>>> 5?"</_questions>
>>>>         <_answers>"15","25","10"</_answers>
>>>>         <_comment>This is an example of a file layout for the 
>>>> LoopCard Software By
>>>>Alex Curtis</_comment>
>>>></loopcardprj>
>>> 
>>> The XML is well-formed; but I would rather use this structure, in 
>>> order to avoid complex application logic to associate a question with
> 
>>> its answer:
>>> 
>>>          <_questions>
>>>                  <question>
>>>                          <q>What Is 5 x 3?</q>
>>>                           15 
>>>                  </question>
>>>                  <question>
>>>                          <q>What Is 5 x 5?</q>
>>>                           25 
>>>                  </question>
>>>                  <question>
>>>                          <q>What Is 5 + 5?</q>
>>>                           10 
>>>                  </question>
>>>          </_questions>
>>> 
>>>>(IF OK): I need to know how to use the parser to parse this file &
>> dump
>> the
>>>>data into the correct variables. I read that DOMBuilder was the class
>> to
>>>>use???
>>> 
>>> DOMBuilder will build a DOM tree that you will have to navigate 
>>> (DOMDocument->getDocumentElement() will give you the pointer to the 
>>> "loopcardprj" node; from there, getFirstChild()/getNextSibling() will
> 
>>> give you either text nodes containing whitespace or the 
>>> "_prjsetup"/"_questions" element; and so on.. until you will find 
>>> some text nodes containing the real data).
>>> Alternatively you can use a SAXParser or a SAX2XMLReader that will 
>>> convert the file into a sequence of callbacks (start "loopcardprj" 
>>> element; start "_prjsetup" element; start "title" element; found data
> 
>>> "untitled"; end "title" element...); if you just need to convert the 
>>> XML file into a C++ data structure, this would be the choice I would
>> made.
>>> 
>>> Alberto
>>> 
>>> 
>>>>Please If you could help, im really new to this XML / Parsing
>> Business...
>>>>
>>>>
>>>>Many Thanks
>>>>-Alex
>>>>--
>>>>View this message in context: 
>>>>http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7884089
>>>>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>>> 
>>> 
>>> 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7891431
>> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7891820
> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7892561
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


RE: Starting To Use Xerces

Posted by Jesse Pelton <js...@PKC.com>.
I haven't used XSD myself.  One of its authors subscribes to this list
and may respond, but I'd try one of the lists specific to the product,
listed at http://codesynthesis.com/support/. 

-----Original Message-----
From: appleGuy [mailto:alx.curtis@gmail.com] 
Sent: Friday, December 15, 2006 8:56 AM
To: c-users@xerces.apache.org
Subject: RE: Starting To Use Xerces


Hi,

This Code Synthesis XSD  Looks like just what i Need but I just Need
clarification.

Ive got a project Class, it has variables that I need the XML Data to
fill.
There are also containers (lists) that need to be filled. All in the
same
class.

Would I use C++/Tree or C++/Parser? I need something really easy to use
as
time is short..

After further reading im not too bothard about using seperate methods of
reading & writing XML docs.

Cheers
Alex


Jesse Pelton wrote:
> 
> You don't necessarily have to use the same method for reading
documents
> that you use for generating them.  SAX is a great interface for
building
> up data structures from a document.  It's fast, flexible, and
efficient.
> DOM parsing also has its uses, of course, but it tends to be more
> cumbersome, and uses much more memory.  DOM shines in document
creation,
> however.  So I tend to use SAX for parsing and DOM for generating
> documents, and I suspect that I'm in good company.  It makes a lot of
> sense when you're using XML to represent data that already has an
> in-memory representation, that is, when XML is just a serialization
> format for your data.
> 
> Nonetheless, it sounds like the DOM does what you need.
> 
> You might want to look at the sample apps (DOMPrint, for instance) to
> get a sense of how to use the DOM APIs.  Also consider XML data
binding
> tools such as Code Synthesis XSD
> (http://codesynthesis.com/products/xsd/), which is based on Xerces.
> 
> -----Original Message-----
> From: appleGuy [mailto:alx.curtis@gmail.com] 
> Sent: Friday, December 15, 2006 8:29 AM
> To: c-users@xerces.apache.org
> Subject: Re: Starting To Use Xerces
> 
> 
> Hi,
> 
> Ok I made the changes to the XML file.
> I think im going to use Dom, i read that it allows saving & creating
XML
> files. I need to use this eventually & because I have a short
timeframe
> I
> just want to get used to one method. IIs this Ok, will Dom Fufil my
> needs?
> 
> Also How would I start to impliment the Dom (for reading files)...
dont
> see
> a constructor anywhere in the docs...Is it createDOMBuilder ??
> 
> Cheers
> Alex
> 
> 
> Alberto Massari wrote:
>> 
>> At 16.15 14/12/2006 -0800, appleGuy wrote:
>> 
>>>Hi,
>>>
>>>This could be quite a long thread, so please bear with me.
>>>Ok ive got Xerces installed & its compiling the example correctly.
>>>
>>>Now im totally new to XML let alone this parser. Ive contructed the
>>>following xml file. I need the file to contain data that can be
parsed
> &
>>>values loaded into predefined variables within my application..
> Firstly I
>>>suppose I need to know if my XML file is ok: (the example uses place
> holders
>>>so author in a real file would be a persons name)
>>>
>>><?xml version="1.0" encoding="ISO-8859-1"?>
>>><loopcardprj>
>>>         <_prjsetup>
>>>                 <title>untitled</title>
>>>                 <author>author</author>
>>>                 <subject>subject</subject>
>>>                 <card>subject</card>
>>>         </_prjsetup>
>>>         <_questions>"What Is 5 x 3?","What Is 5 x 5?","What Is 5 x 
>>> 5?"</_questions>
>>>         <_answers>"15","25","10"</_answers>
>>>         <_comment>This is an example of a file layout for the 
>>> LoopCard Software By
>>>Alex Curtis</_comment>
>>></loopcardprj>
>> 
>> The XML is well-formed; but I would rather use this structure, in 
>> order to avoid complex application logic to associate a question with

>> its answer:
>> 
>>          <_questions>
>>                  <question>
>>                          <q>What Is 5 x 3?</q>
>>                           15 
>>                  </question>
>>                  <question>
>>                          <q>What Is 5 x 5?</q>
>>                           25 
>>                  </question>
>>                  <question>
>>                          <q>What Is 5 + 5?</q>
>>                           10 
>>                  </question>
>>          </_questions>
>> 
>>>(IF OK): I need to know how to use the parser to parse this file &
> dump
> the
>>>data into the correct variables. I read that DOMBuilder was the class
> to
>>>use???
>> 
>> DOMBuilder will build a DOM tree that you will have to navigate 
>> (DOMDocument->getDocumentElement() will give you the pointer to the 
>> "loopcardprj" node; from there, getFirstChild()/getNextSibling() will

>> give you either text nodes containing whitespace or the 
>> "_prjsetup"/"_questions" element; and so on.. until you will find 
>> some text nodes containing the real data).
>> Alternatively you can use a SAXParser or a SAX2XMLReader that will 
>> convert the file into a sequence of callbacks (start "loopcardprj" 
>> element; start "_prjsetup" element; start "title" element; found data

>> "untitled"; end "title" element...); if you just need to convert the 
>> XML file into a C++ data structure, this would be the choice I would
> made.
>> 
>> Alberto
>> 
>> 
>>>Please If you could help, im really new to this XML / Parsing
> Business...
>>>
>>>
>>>Many Thanks
>>>-Alex
>>>--
>>>View this message in context: 
>>>http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7884089
>>>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7891431
> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7891820
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


RE: Starting To Use Xerces

Posted by appleGuy <al...@gmail.com>.
Hi,

This Code Synthesis XSD  Looks like just what i Need but I just Need
clarification.

Ive got a project Class, it has variables that I need the XML Data to fill.
There are also containers (lists) that need to be filled. All in the same
class.

Would I use C++/Tree or C++/Parser? I need something really easy to use as
time is short..

After further reading im not too bothard about using seperate methods of
reading & writing XML docs.

Cheers
Alex


Jesse Pelton wrote:
> 
> You don't necessarily have to use the same method for reading documents
> that you use for generating them.  SAX is a great interface for building
> up data structures from a document.  It's fast, flexible, and efficient.
> DOM parsing also has its uses, of course, but it tends to be more
> cumbersome, and uses much more memory.  DOM shines in document creation,
> however.  So I tend to use SAX for parsing and DOM for generating
> documents, and I suspect that I'm in good company.  It makes a lot of
> sense when you're using XML to represent data that already has an
> in-memory representation, that is, when XML is just a serialization
> format for your data.
> 
> Nonetheless, it sounds like the DOM does what you need.
> 
> You might want to look at the sample apps (DOMPrint, for instance) to
> get a sense of how to use the DOM APIs.  Also consider XML data binding
> tools such as Code Synthesis XSD
> (http://codesynthesis.com/products/xsd/), which is based on Xerces.
> 
> -----Original Message-----
> From: appleGuy [mailto:alx.curtis@gmail.com] 
> Sent: Friday, December 15, 2006 8:29 AM
> To: c-users@xerces.apache.org
> Subject: Re: Starting To Use Xerces
> 
> 
> Hi,
> 
> Ok I made the changes to the XML file.
> I think im going to use Dom, i read that it allows saving & creating XML
> files. I need to use this eventually & because I have a short timeframe
> I
> just want to get used to one method. IIs this Ok, will Dom Fufil my
> needs?
> 
> Also How would I start to impliment the Dom (for reading files)... dont
> see
> a constructor anywhere in the docs...Is it createDOMBuilder ??
> 
> Cheers
> Alex
> 
> 
> Alberto Massari wrote:
>> 
>> At 16.15 14/12/2006 -0800, appleGuy wrote:
>> 
>>>Hi,
>>>
>>>This could be quite a long thread, so please bear with me.
>>>Ok ive got Xerces installed & its compiling the example correctly.
>>>
>>>Now im totally new to XML let alone this parser. Ive contructed the
>>>following xml file. I need the file to contain data that can be parsed
> &
>>>values loaded into predefined variables within my application..
> Firstly I
>>>suppose I need to know if my XML file is ok: (the example uses place
> holders
>>>so author in a real file would be a persons name)
>>>
>>><?xml version="1.0" encoding="ISO-8859-1"?>
>>><loopcardprj>
>>>         <_prjsetup>
>>>                 <title>untitled</title>
>>>                 <author>author</author>
>>>                 <subject>subject</subject>
>>>                 <card>subject</card>
>>>         </_prjsetup>
>>>         <_questions>"What Is 5 x 3?","What Is 5 x 5?","What Is 5 x 
>>> 5?"</_questions>
>>>         <_answers>"15","25","10"</_answers>
>>>         <_comment>This is an example of a file layout for the 
>>> LoopCard Software By
>>>Alex Curtis</_comment>
>>></loopcardprj>
>> 
>> The XML is well-formed; but I would rather use this structure, in 
>> order to avoid complex application logic to associate a question with 
>> its answer:
>> 
>>          <_questions>
>>                  <question>
>>                          <q>What Is 5 x 3?</q>
>>                           15 
>>                  </question>
>>                  <question>
>>                          <q>What Is 5 x 5?</q>
>>                           25 
>>                  </question>
>>                  <question>
>>                          <q>What Is 5 + 5?</q>
>>                           10 
>>                  </question>
>>          </_questions>
>> 
>>>(IF OK): I need to know how to use the parser to parse this file &
> dump
> the
>>>data into the correct variables. I read that DOMBuilder was the class
> to
>>>use???
>> 
>> DOMBuilder will build a DOM tree that you will have to navigate 
>> (DOMDocument->getDocumentElement() will give you the pointer to the 
>> "loopcardprj" node; from there, getFirstChild()/getNextSibling() will 
>> give you either text nodes containing whitespace or the 
>> "_prjsetup"/"_questions" element; and so on.. until you will find 
>> some text nodes containing the real data).
>> Alternatively you can use a SAXParser or a SAX2XMLReader that will 
>> convert the file into a sequence of callbacks (start "loopcardprj" 
>> element; start "_prjsetup" element; start "title" element; found data 
>> "untitled"; end "title" element...); if you just need to convert the 
>> XML file into a C++ data structure, this would be the choice I would
> made.
>> 
>> Alberto
>> 
>> 
>>>Please If you could help, im really new to this XML / Parsing
> Business...
>>>
>>>
>>>Many Thanks
>>>-Alex
>>>--
>>>View this message in context: 
>>>http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7884089
>>>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7891431
> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7891820
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


RE: Starting To Use Xerces

Posted by Jesse Pelton <js...@PKC.com>.
You don't necessarily have to use the same method for reading documents
that you use for generating them.  SAX is a great interface for building
up data structures from a document.  It's fast, flexible, and efficient.
DOM parsing also has its uses, of course, but it tends to be more
cumbersome, and uses much more memory.  DOM shines in document creation,
however.  So I tend to use SAX for parsing and DOM for generating
documents, and I suspect that I'm in good company.  It makes a lot of
sense when you're using XML to represent data that already has an
in-memory representation, that is, when XML is just a serialization
format for your data.

Nonetheless, it sounds like the DOM does what you need.

You might want to look at the sample apps (DOMPrint, for instance) to
get a sense of how to use the DOM APIs.  Also consider XML data binding
tools such as Code Synthesis XSD
(http://codesynthesis.com/products/xsd/), which is based on Xerces.

-----Original Message-----
From: appleGuy [mailto:alx.curtis@gmail.com] 
Sent: Friday, December 15, 2006 8:29 AM
To: c-users@xerces.apache.org
Subject: Re: Starting To Use Xerces


Hi,

Ok I made the changes to the XML file.
I think im going to use Dom, i read that it allows saving & creating XML
files. I need to use this eventually & because I have a short timeframe
I
just want to get used to one method. IIs this Ok, will Dom Fufil my
needs?

Also How would I start to impliment the Dom (for reading files)... dont
see
a constructor anywhere in the docs...Is it createDOMBuilder ??

Cheers
Alex


Alberto Massari wrote:
> 
> At 16.15 14/12/2006 -0800, appleGuy wrote:
> 
>>Hi,
>>
>>This could be quite a long thread, so please bear with me.
>>Ok ive got Xerces installed & its compiling the example correctly.
>>
>>Now im totally new to XML let alone this parser. Ive contructed the
>>following xml file. I need the file to contain data that can be parsed
&
>>values loaded into predefined variables within my application..
Firstly I
>>suppose I need to know if my XML file is ok: (the example uses place
holders
>>so author in a real file would be a persons name)
>>
>><?xml version="1.0" encoding="ISO-8859-1"?>
>><loopcardprj>
>>         <_prjsetup>
>>                 <title>untitled</title>
>>                 <author>author</author>
>>                 <subject>subject</subject>
>>                 <card>subject</card>
>>         </_prjsetup>
>>         <_questions>"What Is 5 x 3?","What Is 5 x 5?","What Is 5 x 
>> 5?"</_questions>
>>         <_answers>"15","25","10"</_answers>
>>         <_comment>This is an example of a file layout for the 
>> LoopCard Software By
>>Alex Curtis</_comment>
>></loopcardprj>
> 
> The XML is well-formed; but I would rather use this structure, in 
> order to avoid complex application logic to associate a question with 
> its answer:
> 
>          <_questions>
>                  <question>
>                          <q>What Is 5 x 3?</q>
>                           15 
>                  </question>
>                  <question>
>                          <q>What Is 5 x 5?</q>
>                           25 
>                  </question>
>                  <question>
>                          <q>What Is 5 + 5?</q>
>                           10 
>                  </question>
>          </_questions>
> 
>>(IF OK): I need to know how to use the parser to parse this file &
dump
the
>>data into the correct variables. I read that DOMBuilder was the class
to
>>use???
> 
> DOMBuilder will build a DOM tree that you will have to navigate 
> (DOMDocument->getDocumentElement() will give you the pointer to the 
> "loopcardprj" node; from there, getFirstChild()/getNextSibling() will 
> give you either text nodes containing whitespace or the 
> "_prjsetup"/"_questions" element; and so on.. until you will find 
> some text nodes containing the real data).
> Alternatively you can use a SAXParser or a SAX2XMLReader that will 
> convert the file into a sequence of callbacks (start "loopcardprj" 
> element; start "_prjsetup" element; start "title" element; found data 
> "untitled"; end "title" element...); if you just need to convert the 
> XML file into a C++ data structure, this would be the choice I would
made.
> 
> Alberto
> 
> 
>>Please If you could help, im really new to this XML / Parsing
Business...
>>
>>
>>Many Thanks
>>-Alex
>>--
>>View this message in context: 
>>http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7884089
>>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7891431
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Starting To Use Xerces

Posted by appleGuy <al...@gmail.com>.
Hi,

Ok I made the changes to the XML file.
I think im going to use Dom, i read that it allows saving & creating XML
files. I need to use this eventually & because I have a short timeframe I
just want to get used to one method. IIs this Ok, will Dom Fufil my needs?

Also How would I start to impliment the Dom (for reading files)... dont see
a constructor anywhere in the docs...Is it createDOMBuilder ??

Cheers
Alex


Alberto Massari wrote:
> 
> At 16.15 14/12/2006 -0800, appleGuy wrote:
> 
>>Hi,
>>
>>This could be quite a long thread, so please bear with me.
>>Ok ive got Xerces installed & its compiling the example correctly.
>>
>>Now im totally new to XML let alone this parser. Ive contructed the
>>following xml file. I need the file to contain data that can be parsed &
>>values loaded into predefined variables within my application.. Firstly I
>>suppose I need to know if my XML file is ok: (the example uses place
holders
>>so author in a real file would be a persons name)
>>
>><?xml version="1.0" encoding="ISO-8859-1"?>
>><loopcardprj>
>>         <_prjsetup>
>>                 <title>untitled</title>
>>                 <author>author</author>
>>                 <subject>subject</subject>
>>                 <card>subject</card>
>>         </_prjsetup>
>>         <_questions>"What Is 5 x 3?","What Is 5 x 5?","What Is 5 x 
>> 5?"</_questions>
>>         <_answers>"15","25","10"</_answers>
>>         <_comment>This is an example of a file layout for the 
>> LoopCard Software By
>>Alex Curtis</_comment>
>></loopcardprj>
> 
> The XML is well-formed; but I would rather use this structure, in 
> order to avoid complex application logic to associate a question with 
> its answer:
> 
>          <_questions>
>                  <question>
>                          <q>What Is 5 x 3?</q>
>                           15 
>                  </question>
>                  <question>
>                          <q>What Is 5 x 5?</q>
>                           25 
>                  </question>
>                  <question>
>                          <q>What Is 5 + 5?</q>
>                           10 
>                  </question>
>          </_questions>
> 
>>(IF OK): I need to know how to use the parser to parse this file & dump
the
>>data into the correct variables. I read that DOMBuilder was the class to
>>use???
> 
> DOMBuilder will build a DOM tree that you will have to navigate 
> (DOMDocument->getDocumentElement() will give you the pointer to the 
> "loopcardprj" node; from there, getFirstChild()/getNextSibling() will 
> give you either text nodes containing whitespace or the 
> "_prjsetup"/"_questions" element; and so on.. until you will find 
> some text nodes containing the real data).
> Alternatively you can use a SAXParser or a SAX2XMLReader that will 
> convert the file into a sequence of callbacks (start "loopcardprj" 
> element; start "_prjsetup" element; start "title" element; found data 
> "untitled"; end "title" element...); if you just need to convert the 
> XML file into a C++ data structure, this would be the choice I would made.
> 
> Alberto
> 
> 
>>Please If you could help, im really new to this XML / Parsing Business...
>>
>>
>>Many Thanks
>>-Alex
>>--
>>View this message in context: 
>>http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7884089
>>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7891431
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Starting To Use Xerces

Posted by Alberto Massari <am...@datadirect.com>.
At 16.15 14/12/2006 -0800, appleGuy wrote:

>Hi,
>
>This could be quite a long thread, so please bear with me.
>Ok ive got Xerces installed & its compiling the example correctly.
>
>Now im totally new to XML let alone this parser. Ive contructed the
>following xml file. I need the file to contain data that can be parsed &
>values loaded into predefined variables within my application.. Firstly I
>suppose I need to know if my XML file is ok: (the example uses place holders
>so author in a real file would be a persons name)
>
><?xml version="1.0" encoding="ISO-8859-1"?>
><loopcardprj>
>         <_prjsetup>
>                 <title>untitled</title>
>                 <author>author</author>
>                 <subject>subject</subject>
>                 <card>subject</card>
>         </_prjsetup>
>         <_questions>"What Is 5 x 3?","What Is 5 x 5?","What Is 5 x 
> 5?"</_questions>
>         <_answers>"15","25","10"</_answers>
>         <_comment>This is an example of a file layout for the 
> LoopCard Software By
>Alex Curtis</_comment>
></loopcardprj>

The XML is well-formed; but I would rather use this structure, in 
order to avoid complex application logic to associate a question with 
its answer:

         <_questions>
                 <question>
                         <q>What Is 5 x 3?</q>
                         <a>15</a>
                 </question>
                 <question>
                         <q>What Is 5 x 5?</q>
                         <a>25</a>
                 </question>
                 <question>
                         <q>What Is 5 + 5?</q>
                         <a>10</a>
                 </question>
         </_questions>

>(IF OK): I need to know how to use the parser to parse this file & dump the
>data into the correct variables. I read that DOMBuilder was the class to
>use???

DOMBuilder will build a DOM tree that you will have to navigate 
(DOMDocument->getDocumentElement() will give you the pointer to the 
"loopcardprj" node; from there, getFirstChild()/getNextSibling() will 
give you either text nodes containing whitespace or the 
"_prjsetup"/"_questions" element; and so on.. until you will find 
some text nodes containing the real data).
Alternatively you can use a SAXParser or a SAX2XMLReader that will 
convert the file into a sequence of callbacks (start "loopcardprj" 
element; start "_prjsetup" element; start "title" element; found data 
"untitled"; end "title" element...); if you just need to convert the 
XML file into a C++ data structure, this would be the choice I would made.

Alberto


>Please If you could help, im really new to this XML / Parsing Business...
>
>
>Many Thanks
>-Alex
>--
>View this message in context: 
>http://www.nabble.com/Starting-To-Use-Xerces-tf2824403.html#a7884089
>Sent from the Xerces - C - Users mailing list archive at Nabble.com.