0

This is the XML code:

<?xml version="1.0" encoding="utf-8"?>
<Enemies>
    <Enemy id="001" name="Bandit" combatstyle="1" aitype="1" difficulty="1" imgsheet="001.png" level="2" hp"5" />
    <Enemy id="005" name="Dragon" combatstyle="1" aitype="1" difficulty="1" imgsheet="002.png" level="5" hp"50" />
</Enemies>

And this it the code i use to search the content:

pugi::xml_document doc;

pugi::xml_parse_result result = doc.load_file("assets/enemies.xml");       

pugi::xml_node nodes = doc.child("Enemies");

for (pugi::xml_node tool = nodes.child("Enemy"); tool; tool = tool.next_sibling("Enemy"))
   {
        //only here to check if it's working
        string lol = tool.attribute("name").as_string();
        int hi = tool.attribute("id").as_int();
    }

When the loop executes tool = tool.next_sibling("Enemy") it reaches the end and jumps out of the loop. I can get the information just fine from the first enemy, so i'm doing something right.

JohanLejdung
  • 353
  • 1
  • 4
  • 18

1 Answers1

0

I don't know what i did. But now it seems to work. This is really weird, i didn't change a thing to the class and now it works.

Anyways, all is good!

JohanLejdung
  • 353
  • 1
  • 4
  • 18
  • I'm facing the same issue and this answer is frustrating. Computer executes exactly what you code. No changes means no fix. Something must have changed somewhere. – Sin Han Jinn May 12 '20 at 05:46
  • 1
    This is 7 years ago so I cannot tell you what I did. But considering that I didn't know what changed, and that I didn't change the class. Maybe it had something to do with the compiled code being outdated? I hope you are able to find the issue! – JohanLejdung May 13 '20 at 15:54
  • 1
    Hey @JohanLejdung, It's so nice of you to reply! My apologies for I was pure ranting. I manage to solve my issue and it was due to my function parameters being written wrongly. This guy's sentence (directly quoted) `"The important part is child = child.next_sibling(), not parent.next_sibling()."` helped me! - [link](https://stackoverflow.com/a/6046927/12128167). Based on your pasted code, yours looks fine. However, I'm posting this here for it may help others. Have a nice day! – Sin Han Jinn May 14 '20 at 01:25
  • That's great to hear! – JohanLejdung May 16 '20 at 12:13