Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#13297 closed defect (wontfix)

wxXmlDocument save (OutputNode) does not output wxXML_ELEMENT_NODE content

Reported by: chief Owned by:
Priority: normal Milestone:
Component: base Version: 2.9.1
Keywords: wxXmlDocument XML Cc:
Blocked By: Blocking:
Patch: yes

Description

G’day All,

And especially Vadim who helped me a few (6 or 7 ?) years ago with (my) problems with wxSockets.

Hopefully this pays some of that back – firstly platform and version specifications.

WX : 2.8.11 AND 2.9.1
OS : Windows XP (SP3) AND Windows 7
COMPILER: VC9 IDE

The above is (I think) not relevant to this particular issue from what I have seen of the code, but deadlines prevent me from a full investigation.

I have some code which does something like the following (pScenarioNode is a wxXMLNode*):
.
.
.
lastNode = nextNode;
pScenarioNode->InsertChildAfter((nextNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("BusinessUnit"), pScenario->GetBusinessUnit())),lastNode);
lastNode = nextNode;
pScenarioNode->InsertChildAfter((nextNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("Location"), pScenario->GetLocation())),lastNode);
.
.
.

This creates (or should create) an XML fragment which appears as follows:

.
.
.

<BusinessUnit>Some Business Unit</BusinessUnit>
<Location>Somewhere</Location>

.
.
.
Etc.

I couldn’t get this to generate the expected output in a file when calling wxXmlDocument.Save() – I got the XML structure but not the content.

I think (from memory), version 2.8.11 gave me little more than the version and encoding information.
I tracked this down eventually, and made some changes to xml.cpp which fixd the issue (at least for me), but forgot about it until I moved to version 2.9.1 when I was getting all the elements, but no content.

The above XML fragement, effectively appeared as follows:

.
.
.

<BusinessUnit/>
<Location/>

.
.
.

It would appear that the OutputNode() function was not outputting an XMLNode’s content.

Attached is the modified file (xml.cpp zipped using winzip) that I am now using (from the 2.9.1 release), which is far from perfect, but suits my needs and I think solves the issue in some way that may warrant inclusion in a future release.

I added a #ifdef so I could output empty elements as either:

<foo/>

OR

<foo>
</foo>

Personally, I would like to see it in an OutputElementNode() function which outputs everything an element can encapsulate.

The changes are confined to a section which starts and ends with ACF (i.e. search for this)

A final question.

What is the future of wxXML ? I think I read somewhere it will be dropped in a future release – is this the case ?
Will it be replaced by something else or simply go missing ?
I have previously used Xerces in conjunction with wxWidgets but would like to plan for this sooner rather than later if it is inevitable, especially considering how complex Xerces has become since 3.x

Thanks for all the hard work and a fantastic library from a user of almost 10 years.

Attachments (1)

xml.cpp.patch download (2.2 KB) - added by chief 3 years ago.
Patch against latest (trunk) version

Download all attachments as: .zip

Change History (4)

Changed 3 years ago by chief

Patch against latest (trunk) version

comment:1 Changed 3 years ago by chief

Sorry - copied and pasted original email which did have the modified file attached.
It is obviously not attached to this ticket, but I did include a patch file.

comment:2 Changed 3 years ago by vaclavslavik

  • Resolution set to wontfix
  • Status changed from new to closed

"Content" only makes sense for XML nodes of type wxXML_TEXT_NODE or wxXML_CDATA_SECTION_NODE (well, or comments and some other stuff, but that's not in this context), not for elements, so you need to create a text node child. This is same as in DOM, which wxXmlNode is modeled after, BTW. I guess we should add an assert warning about this.

IOW, this patch shouldn't be applied.

comment:3 Changed 3 years ago by VS

(In [68283]) Add check to prevent creation of element wxXmlNodes with content data.

Just like in the DOM, only text, ctype etc. nodes have textual content,
elements don't.

See #13297.

Note: See TracTickets for help on using tickets.