Author Topic: Problem parsing XML  (Read 242 times)

Offline msagner

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • Email
Problem parsing XML
« on: May 02, 2010, 09:07:46 »
Hi,
I'm trying to parse an xml file, but having problems accessing the children list of the root element:
In the code below, the element name returned for the children is always "root", although this name does not appear anywhere in the xml.

Any hint appreciated.

   XMLElement& root = m_pxml->GetRootElement();
   unsigned uNbrEthercatBlocks = root.GetAllChildrenNum();
   
   for(vector<CCDBItem>::iterator it = m_cdb.getItemlist()->begin(); it != m_cdb.getItemlist()->end(); it++)
   {
      for(unsigned uBlockIdx = 0; uBlockIdx < uNbrEthercatBlocks; uBlockIdx ++)
      {
         vector<XMLElement> children = root.GetChildren();
         vector<XMLElement>::iterator iter;
         for (iter = children.begin(); iter != children.end(); ++iter)
         {
            XMLElement &e = *iter;
            char name[256] = {'\0'};
            e.GetElementName (name);
         }   
      }
   }

Offline Michael

  • Administrator
  • Super Member
  • ******************
  • Posts: 1069
  • Karma: 32
    • TurboIRC.COM
Re: Problem parsing XML
« Reply #1 on: May 02, 2010, 09:09:03 »
Try a reference.

vector<XMLElement>& children = root.GetChildren();

Offline msagner

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • Email
Re: Problem parsing XML
« Reply #2 on: May 02, 2010, 09:50:04 »
Thanks for the quick reply, on a sunday to boot - but sorry, using a reference didn't help.

I did some more debugging and found that the root element contained six children - which is correct -
and each of the children had the name "root" (which is NOT correct).
Also, the children had an invalid parent pointer (0xdcdcdc.. or something, indicating it was not initialized),
and the children did not have any children themselves, which is also not correct.

The xml was generated by a vendor-supplied tool which might not be totally bug-free, also it loads into your tool TXML without a snag and shows everything in the correct way.

What could I be doing wrong?

Offline Michael

  • Administrator
  • Super Member
  • ******************
  • Posts: 1069
  • Karma: 32
    • TurboIRC.COM
Re: Problem parsing XML
« Reply #3 on: May 02, 2010, 10:16:14 »
I will take a deeper look. Basically you are using the STL version which is not as long-term tested as the non STL version - so it could be a bug in the STL implementation. I am very busy these days so if it 's urgent, I 'd suggest you use the non STL until I test it more.




« Last Edit: May 02, 2010, 10:23:37 by Michael »