Re: Iterating through all nodes and attributes of a wxXmlDocument
Maarten Bent <[email protected]>
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
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].
To view this discussion visit https://groups.google.com/d/msgid/wx-users/cbd018ab-176f-43e0-92da-8840772e9fd6%40gmail.com.