XML strangeness

This forum is reserved for everything you want to talk about. It could be about programming, opinions, open source programs, development in general, or just cool stuff to share!
Post Reply
msdobrescu
Knows some wx things
Knows some wx things
Posts: 35
Joined: Wed Sep 08, 2004 6:22 am

XML strangeness

Post by msdobrescu » Sat Apr 12, 2008 9:57 am

Hello,

First of all, I am a newbie to XML and I might do something wrong..
I have tried to use XML as config file. Then I faced the following issue:

Assume I have a structure like this:

<?xml version="1.0" encoding="utf-8"?>
<RootNode>
<Node2></Node2>
<Node1>node one text</Node1>
</RootNode>

I wish to have a null string in Node2 (i.e. "").

The wxXML* classes won't find any text node in Node2.

Ideally, I would make a difference between the <Node2/> and <Node2></Node2>, so in the first case I would have no text node in Node2 and in the second case, a text node having "" text inside. But this is not implemented in wxXML* classes.

wxXMLDocument class has the wxXMLDOC_KEEP_WHITESPACE_NODES flag that should not transform the node2 from <Node2></Node2> to <Node2/>. With this flag something annoying happens: some new lines are saved in the document.

This makes difficult to use the wxXML* classes for writing a configuration class, even those mentioned here http://wiki.wxwidgets.org/Development:_Todo_List are buggy because of that. They will create many <node/> entries in the same node in case of "" value of the text node.

What do you think?
How could it be done?

Yours,
Mike

Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank » Sat Apr 12, 2008 12:08 pm

You can't.

The XML-Standard (see w3c.org) makes no difference between <node/> and <node></node>. It's just syntactic sugar for the same thing: An empty node.

If you want do have a diffence like eg '' and null in a database, you have to encode it on your own.

msdobrescu
Knows some wx things
Knows some wx things
Posts: 35
Joined: Wed Sep 08, 2004 6:22 am

Post by msdobrescu » Sat Apr 12, 2008 7:02 pm

Yes,

But why does it save <node></node> first, and next time <node/>?
Why doesn't it save <node>""</node> as other implementations?

Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank » Sun Apr 13, 2008 12:57 pm

Because it's wrong.

<node>""</node> is the string "" (the two quote characters), not Empty.

If you want a "" for whatever reason, just set the value of the node to "\"\"" from C++.

Belgabor
I live to help wx-kind
I live to help wx-kind
Posts: 173
Joined: Mon Sep 25, 2006 1:12 pm

Post by Belgabor » Sun Apr 13, 2008 1:24 pm

I also fail to see how any of this prevents you from writing a working xml-based conf implementation...

msdobrescu
Knows some wx things
Knows some wx things
Posts: 35
Joined: Wed Sep 08, 2004 6:22 am

Post by msdobrescu » Sun Apr 13, 2008 5:10 pm

Since there is no difference between having an empty text node and not having it at all...

Belgabor
I live to help wx-kind
I live to help wx-kind
Posts: 173
Joined: Mon Sep 25, 2006 1:12 pm

Post by Belgabor » Mon Apr 14, 2008 6:48 pm

msdobrescu wrote:Since there is no difference between having an empty text node and not having it at all...
I don't understand, why is that a problem? Just implement the class and corresponding xml format in a way where that difference doesn't matter.

Post Reply