RE: Iterating through all nodes and attributes of a wxXmlDocument
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
Martin, Many thanks for this and apologies for not replying sooner – your message landed in my Junk folder for reasons that are beyond me. Best wishes. Tim From: [email protected] <[email protected]> On Behalf Of Maarten Bent Sent: 25 February 2025 23:44 To: [email protected] Subject: Re: Iterating through all nodes and attributes of a wxXmlDocument Hi, Looks like you have infinite iterations in both for-loops. Because you do not assign the next attribute/childNode. For example, the last component in the second for loop should be: childNode = childNode->GetNext(). Maarten On 25 Feb 2025 14:25, Tim Burgess wrote: Hi, It’s been a while since I had to recurse anything, but I can’t see how to do this. I’m trying to construct a wxString that represents the text content of a class derived from wxXmlDocument. Here’s what I have: wxString MyDerivedXMLDocClass::GetTextContent() { wxString result = wxEmptyString; wxXmlNode* const root = this->GetRoot(); if (root == nullptr) { return wxEmptyString; } return GetNodeText(root); } wxString MyDerivedXMLDocClass::GetNodeText(wxXmlNode * myNode) { wxString result = wxEmptyString; if (myNode->GetType() == wxXML_ELEMENT_NODE) { result = myNode->GetName(); // Get all attributes for (const wxXmlAttribute* attribute = myNode->GetAttributes(); attribute != NULL; attribute->GetNext()) { result += attribute->GetName() + attribute->GetValue() + "\n"; } } else if (myNode->GetType() == wxXML_TEXT_NODE) { result += myNode->GetContent() + "\n"; } for (wxXmlNode * childNode = myNode->GetChildren(); childNode != NULL; childNode->GetNext()) { result += GetNodeText(childNode); } return result; } The code throws an exception, but I can’t tell quite where as I’m a blind programmer and the exception blows out my screen reader. Any advice would be most welcome. Tim -- Please read https://www.wxwidgets.org/support/mlhowto.htm before posting. --- You received this message because you are subscribed to the Google Groups "wx-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/wx-users/005801db8788%24c5fa7870%2451ef6950%24%40raisedbar.net <https://groups.google.com/d/msgid/wx-users/005801db8788%24c5fa7870%2451ef6950%24%40raisedbar.net?utm_medium=email&utm_source=footer> . -- Please read https://www.wxwidgets.org/support/mlhowto.htm before posting. --- You received this message because you are subscribed to the Google Groups "wx-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]> . To view this discussion visit https://groups.google.com/d/msgid/wx-users/cbd018ab-176f-43e0-92da-8840772e9fd6%40gmail.com <https://groups.google.com/d/msgid/wx-users/cbd018ab-176f-43e0-92da-8840772e9fd6%40gmail.com?utm_medium=email&utm_source=footer> . -- Please read https://www.wxwidgets.org/support/mlhowto.htm before posting. --- You received this message because you are subscribed to the Google Groups "wx-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/wx-users/00ad01db8f51%24e15ad170%24a4107450%24%40gmail.com.