Iterating through all nodes and attributes of a wxXmlDocument
"Tim Burgess" <[email protected]>
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
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.