If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Hi friends,
I have problem I cannot spot the problem.
I have XML file reader that I use as setting class. I can write fine but I cannot read! I have followed the code with debugger and I can see each time it gets empty variable (It catches the settings well but cannot get the value)
Anyone to test/help me spot what i'm doing wrong
Thanks
wxString GetNodeContent(const wxXmlNode* node)
{
const wxXmlNode* n = node;
if (n == NULL) return wxEmptyString;
n = n->GetChildren();
while (n)
{
if (n->GetType() == wxXML_TEXT_NODE ||
n->GetType() == wxXML_CDATA_SECTION_NODE)
return n->GetContent();
n = n->GetNext();
}
return wxEmptyString;
}
This would return the first text node content. In case the content of your node has a more complex form you might need to concatenate the different parts in the while loop.
evstevemd wrote:I would be happy to tell me what I was doing wrong there!
Well, it depends on the XML node type what method GetContent returns. The XML node settingNode in your example is an element node for which GetContent returns an empty string, but the node has a child node of type text which represents the textual content between the elements <settingNode> and </settingNode> and for such nodes of type textGetContent returns this textual content.
evstevemd wrote:I would be happy to tell me what I was doing wrong there!
Well, it depends on the XML node type what method GetContent returns. The XML node settingNode in your example is an element node for which GetContent returns an empty string, but the node has a child node of type text which represents the textual content between the elements <settingNode> and </settingNode> and for such nodes of type textGetContent returns this textual content.
Regards,
Ulrich
Clear now,
thanks
Chief Justice: We have trouble dear citizens! Citizens: What it is his honor? Chief Justice:Our president is an atheist, who will he swear to?
Because node content is a child for it's node tag element you have to use GetChildren() once more.
For such simple XML Node you can use a simplier method: