Re: xml

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 04/17/04


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



Relevant Pages

  • Re: Latest version of glossary
    ... such as XML, refer to the use of the term within that "namespace" using ... An n-dimensional data structure, S, is one where each element of S ... Whenever mathematics is applied to anything, ... associative array (while trying to do something in JavaScript, ...
    (comp.databases.theory)
  • Re: Serialization with XmlSerializer: how to set the XML root node to something different from <
    ... Daniel Cazzulino [MVP XML] ... >> So if it is an array of Foo that is being returned, ... > The point here is not controlling the serialization of the elements of an ... >> modified root node should de-serialize just fine. ...
    (microsoft.public.dotnet.xml)
  • Re: Sending data in a DOM table to the server (with a POST)
    ... I am using Struts now but not using XML. ... have just been able to return an array to a .jsp program. ... The person adds and deletes records from the DOM ...
    (comp.lang.java.help)
  • XML help
    ... I'm 4 months new to python and 4 hours new to XML. ... understand and use the DOM tree walk sample shown at this site: ... walk the tree I temporarily store IDs and DeptValues in lists. ... I then intend to create an array of size determined by the maximum ...
    (comp.lang.python)
  • Re: Serialization with XmlSerializer: how to set the XML root node to something different from <
    ... > So if it is an array of Foo that is being returned, ... The point here is not controlling the serialization of the elements of an ... array, but of the array itself, in other words of the xml root element. ... array is indeed very simple (XmlArrayAttribute and XmlArrayItemAttribute is ...
    (microsoft.public.dotnet.xml)