Could you keep a count of how many values you've set and use it to
determine which one to set next?  Initialize your structure to an empty
state outside the loop(s) and populate it as you find data.

It sounds like you'll have to decide what to do if you encounter more
values than you can store.  If this is true, your document structure
does not mesh well with its memory representation, and you may want to
look for ways to make them more similar, such as having a named document
element for each structure member.  You'd inspect the element name to
decide where to store its value.

> -----Original Message-----
> From: Jones, Brian O. [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, August 17, 2004 9:28 AM
> To: [EMAIL PROTECTED]
> Subject: RE: storing data from XML file into data structure
> 
> What I do to write to a file is use a fout << value. but 
> that's one value at a time.
> 
> 
> 
> but my struct is temp.one = value;
> 
>                  temp.two = should be the next value;
> 
> b/c it's looping thru value by value correct.
> 
> 
> 
> -----Original Message-----
> From: Jesse Pelton [mailto:[EMAIL PROTECTED]
> Sent: Monday, August 16, 2004 10:20 AM
> To: [EMAIL PROTECTED]
> Subject: RE: storing data from XML file into data structure
> 
> 
> You have the following comment (where the real code 
> presumably actually
> 
> writes to a file):
> 
> 
> 
>   //here I have the data that I want to store, 
> 
>   //but I am inside the loop
> 
>   //so I thought I needed all the information 
> 
>   //first b/f storing into my struct.
> 
>   //write the data to a file here
> 
> 
> 
> If you can write to a file here, why can't you store to a struct or
> 
> collection (linked list, vector, array, whatever) of structs?  I can't
> 
> figure out what the looping has to do with it.
> 
> 
> 
> > -----Original Message-----
> 
> > From: Jones, Brian O. [mailto:[EMAIL PROTECTED] 
> 
> > Sent: Monday, August 16, 2004 9:15 AM
> 
> > To: [EMAIL PROTECTED]
> 
> > Subject: RE: storing data from XML file into data structure
> 
> > 
> 
> > Okay here is what I did...don't know if this is right or not.
> 
> > 
> 
> > for(DOMNode * child = root->getFirstChild();
> 
> >     child != 0;
> 
> >     child = child->getNextSibling())
> 
> > {
> 
> >   if(XMLString::compareString(child->getNodeName(),
> 
> >      XMLString::transcode("Entries")) == 0)
> 
> >   {//have to do this to get to the Entries element
> 
> >      for(DOMNode * child2 = child->getFirstChild();
> 
> >          child2 != 0;
> 
> >          child2 = child2->getNextSibling())
> 
> >      {
> 
> >          for(DOMNode * child3 = child2->getFirstChild();
> 
> >          child3 != 0;
> 
> >          child3 = child3->getNextSibling())
> 
> >          {
> 
> >             if(XMLString::compareString(child->getNodeName(),
> 
> >                XMLString::transcode("Table")) == 0)
> 
> >             {//have to do this to get to the Table element
> 
> >                for(DOMNode * child4 = child3->getFirstChild();
> 
> >                    child4 != 0;
> 
> >                    child4 = child4->getNextSibling())
> 
> >                {
> 
> >                    for(DOMNode * child5 = child4->getFirstChild();
> 
> >                    child5 != 0;
> 
> >                    child5 = child5->getNextSibling())
> 
> >                    {
> 
> >                        //here I have the data that I want to store, 
> 
> >                        //but I am inside the loop
> 
> >                        //so I thought I needed all the information 
> 
> >                        //first b/f storing into my struct.
> 
> >                        //write the data to a file here
> 
> >                    }
> 
> >                }                  
> 
> >             }
> 
> >             else
> 
> >             {
> 
> >                //here I have the data that I want to store, 
> 
> > but I am inside the loop
> 
> >                //so I thought I needed all the information 
> 
> > first b/f storing into
> 
> >                // my struct.
> 
> >                //write the data to a file here
> 
> >             }
> 
> >          }
> 
> >      }
> 
> >    }
> 
> > }
> 
> > 
> 
> > Hope this helps...
> 
> > 
> 
> > 
> 
> > -----Original Message-----
> 
> > From: Jesse Pelton [mailto:[EMAIL PROTECTED]
> 
> > Sent: Friday, August 13, 2004 3:14 PM
> 
> > To: [EMAIL PROTECTED]
> 
> > Subject: RE: storing data from XML file into data structure
> 
> > 
> 
> > 
> 
> > I'd consider using SAX rather than DOM for this, but it should be
> 
> > straightforward to accomplish what you want with either.  I 
> think you
> 
> > need to be specific about why you can't.  A code fragment 
> might help.
> 
> > 
> 
> > > -----Original Message-----
> 
> > > From: Jones, Brian O. [mailto:[EMAIL PROTECTED] 
> 
> > > Sent: Friday, August 13, 2004 2:44 PM
> 
> > > To: [EMAIL PROTECTED]
> 
> > > Subject: RE: storing data from XML file into data structure
> 
> > > 
> 
> > > I used several for loops to traverse down to the values that 
> 
> > > I want and I want to take the values and put them into my 
> 
> > > structure, but the section of the xml duplicates per entry 
> 
> > > (for example)
> 
> > > 
> 
> > > struct Two
> 
> > > {
> 
> > >   int value
> 
> > >   int number
> 
> > > }
> 
> > > 
> 
> > > struct One
> 
> > > {
> 
> > >   int start
> 
> > >   int finish
> 
> > >   Two thisvar
> 
> > > }
> 
> > > 
> 
> > > So in my xml file struct one duplicates several times and two 
> 
> > > does as well so I but I know the order of data won't change.
> 
> > > 
> 
> > > -----Original Message-----
> 
> > > From: Jesse Pelton [mailto:[EMAIL PROTECTED]
> 
> > > Sent: Friday, August 13, 2004 2:29 PM
> 
> > > To: [EMAIL PROTECTED]
> 
> > > Subject: RE: storing data from XML file into data structure
> 
> > > 
> 
> > > 
> 
> > > If you can perform those two transformations (XML -> temp 
> 
> > > file and temp
> 
> > > file -> structure), what prevents you from performing a single
> 
> > > transformation (XML -> structure)?  Presumably you've solved 
> 
> > > the problem
> 
> > > of avoiding overwrites in the course of implementing 
> 
> > serialization to
> 
> > > and from your temp file.  The same solution should apply if 
> 
> > > you omit the
> 
> > > serialization and populate your structure as you parse.
> 
> > > 
> 
> > > > -----Original Message-----
> 
> > > > From: Jones, Brian O. [mailto:[EMAIL PROTECTED] 
> 
> > > > Sent: Friday, August 13, 2004 2:05 PM
> 
> > > > To: [EMAIL PROTECTED]
> 
> > > > Subject: storing data from XML file into data structure
> 
> > > > 
> 
> > > > Hi all,
> 
> > > > 
> 
> > > > I am trying to store all the contents of my xml file in a 
> 
> > > > structure when I parse the file, but each section of my file 
> 
> > > > is repeat and I don't want to overwrite what I already have. 
> 
> > > > 
> 
> > > > So my current solution is to parse the file and store the 
> 
> > > > information in a temp file and read the temp file and store 
> 
> > > > the information in my data structure.
> 
> > > > 
> 
> > > > I just want to know if there is a better solution than the 
> 
> > > > one I've tried.
> 
> > > > 
> 
> > > > Brian Jones
> 
> > > > Senior Software Engineer
> 
> > > > (Email) [EMAIL PROTECTED]
> 
> > > > Phone (410) 993-2072
> 
> > > > Fax (410) 981-8381

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to