1

I have xml like this

<w:document>
<w:body>
    <w:p>
        <abra-cadabra>
            <w:t>test</w:t>
        </abra-cadabra>
    </w:p>
    <w:p>
    </w:p>
    <w:p>
        <w:t>test1</w:t>
    </w:p>
</w:body>

I use pugixml to parce it.

pugi::xml_node cur_sibling = cur_node.next_sibling();
    if (cur_sibling.name() == "")
        find_sibling(cur_node.parent());

here cur_node is test node, and next_subling structure looks like this: cur_sibling sorry for russian, it sais can not read memory so I cant do anything with it, and attempt to get it's name cause stack owerflow error. Have no idea what going on, why it didn't return null node?

1 Answers1

0

Your test node does not have a next_sibling, cur_sibling is then an invalid xml_node that you can test with:

if (!cur_sibling)

If you look at the signature of the member function:

const char_t* xml_node::name() const

You can see it's not returning a string but a const char_t*. Then your comparison with operator == is comparing the (different) adresses.

O'Neil
  • 3,790
  • 4
  • 16
  • 30
  • Thanks! It seems to work well, but can you explain me this: as i understood the documentation, when node is last child next_subling returns null node, which's name is an empty string. Although, i used to use the same construction and it worked as i expected. But not this time. What am i missing? – Stupid_Hedgehog Jul 11 '17 at 14:33
  • @Stupid_Hedgehog Indeed, it's [returning an empty string](https://github.com/zeux/pugixml/blob/master/src/pugixml.cpp#L5455) where I expected an assertion. The problem is your comparison. See edited answer. – O'Neil Jul 11 '17 at 14:52
  • @Stupid_Hedgehog You just can't compare `char *` with operator ==, you have to use [`strcmp`](http://en.cppreference.com/w/cpp/string/byte/strcmp). – O'Neil Jul 11 '17 at 15:21