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 wx-users+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/wx-users/005801db8788%24c5fa7870%2451ef6950%24%40raisedbar.net.
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
To view this discussion visit https://groups.google.com/d/msgid/wx-users/cbd018ab-176f-43e0-92da-8840772e9fd6%40gmail.com.
for (auto&& child : node->GetChildrenAsRange()) doSomethingWithNode(child);
for (auto&& attr : node->GetAttributesAsRange()) doSomethingWithAttribute(attr);
The forwarding reference, a feature of template parameters and auto, allow it to copy the const and volatile attributes of the argument.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4164.pdf