Re: xml
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 04/17/04
- Next message: Joseph M. Newcomer: "Re: Dialog inherit"
- Previous message: Joseph M. Newcomer: "Re: VC++ .NET 2002: MFC Errors C2761 & C2447"
- In reply to: Dave: "xml"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 17 Apr 2004 00:16:08 -0400
XML has no good array structure representation. One approach is that you create an array
of pointers into the DOM and as you iterate over the DOM, you fill the array in with these
pointers. Alteratively, you walk the DOM, and at the point where you are sequencing over
the array of elements, you would create an array entry, then walk the DOM and fill the
entry in from the DOM.
If you are using incremental reading, the same principle applies except that you don't
actually walk the DOM; you create the array, then call your reader pointing to the input
stream and the object you've just created, and let your parser fill in the structure.
There are so many XML reader packages out there that there is no one way to do this. My
most recent project used one of the XML readers (which is in a DLL, to conform to the GPL
requirements), and I have an array
typedef CArray<Thing, Thing&> ThingArray;
abd I have a nenber
ThingArray things;
in an Item node.
in one of hte XML tree nodes I'm creating. So what I do is read the XML, which is of the
form
<Stuff> ...
<Item ...>
<Things>
<Thing>...</Thing>
<Thing>...</Thing>
...
<Thing>...</Thing>
</Things>
</Item>
</Stuff>
So when I get to a Things entry, I call
BOOL result = ParseThings(input, Things);
BOOL Item::ParseThings(Stream input, ThingArray & Things)
{
BOOL parsing = TRUE;
while(parsing)
{ /* parse loop */
Thing t;
if(!t.Parse(input, t))
{
DWORD err = ::GetLastError();
switch(err)
{ /* error */
case PARSE_CLOSE_TOKEN:
// we saw </something>
// stream is backed up to reread it
parsing = FALSE;
continue;
case PARSE_SYNTAX_ERROR:
return FALSE;
... maybe other cases for variant syntax
} /* error */
Things.Add(t);
} /* parse loop */
return TRUE;
}
joe
On Fri, 16 Apr 2004 17:57:48 +0200, "Dave" <dbg@012.net.il> wrote:
>Hi,
>How can i read an xml file into a struct`s array ???
>I need to fill array of structs (one struct for eace xml block in the xml
>file)
>like it can be done in dot net xml reader???
>
>Thanks
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: Joseph M. Newcomer: "Re: Dialog inherit"
- Previous message: Joseph M. Newcomer: "Re: VC++ .NET 2002: MFC Errors C2761 & C2447"
- In reply to: Dave: "xml"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|