Re: how to deserialize variable element/node



On 16 Nov 2006 19:54:06 -0800, wpmccormick@xxxxxxxxx wrote:

wpmccormick@xxxxxxxxx wrote:
Gadget wrote:
On 15 Nov 2006 19:28:42 -0800, wpmccormick@xxxxxxxxx wrote:

I've a complex problem:

I need to re-explain this ...

Whether I deserialize this:

<foo>
.......
<bar>sometimes a simple string is here</bar>
.......
</foo>


Or this:

<foo>
.......
<bar>
<zip>sometimes</zip>
<zap>more structure</zap>
<zoo>is here</zoo>
</bar>
.......
</foo>


I want to end up with an object

class foo {
string bar;
baz[] Baz;
}

class {
string zip;
string zap;
string zoo;
}

In the first deserialization case, bar = "sometimes a simple string is
here" and Baz is null. In the second bar is null and zip, zap and zoo
are filled in.

Thanks

OK, so I think you're either misunderstanding XML or trying to use it in an
unorthadox and incorrect manner.
Your two XML fragments would have to be represented in an XML schema by
specifying mixed content, as in one case <bar> contains TEXT and in the
other it contains a set of tags.
Why do you feel the need to read this structure of data? Do you have an
existing data set with this format strings, or are you responsible for
creating the XML?
Your comment that your problem is 'rather simple' is not true. Perhaps your
requirements are, but you seem to have created a very awkward problem for
yourself.
In XML your zip/zap/zoo should be inside a pair of <baz> tags, so you
should have either of the following:
<foo>
<bar />
</baz>
<zip>sometimes</zip>
<zap>more structure</zap>
<zoo>is here</zoo>
</baz>
</foo>

<foo>
<bar>sometimes a simple string is here</bar>
<baz />
</foo>

This means you use the same class for 'foo'. In the first example there is
no string in bar and in second case there is no object assigned to baz
(it's null).
When the deserializer looks at the XML it sees <bar>, reads that it has no
content, and sets it to be empty.
Next, it sees the tag <baz>, creates an instance of a baz, and reads the
content tags, assigning each value to a property in the baz object via the
reflection detected properties.
If baz is an empty tag then the object is set to null.

This weird mixing of meanings in XML produce ambiguity that the built-in
serializer/deserializer can not resolve and won't even try to.

Cheers,
Gadget
.



Relevant Pages

  • Re: OT: Why is C so popular?
    ... > about the indent program at the time? ... if foo: ...
    (Debian-User)
  • Re: how to deserialize variable element/node
    ... string bar; ... baz[] Baz; ... Your two XML fragments would have to be represented in an XML schema by ...
    (microsoft.public.dotnet.xml)
  • Re: Regular Expressions...
    ... (foo, bar, baz) ... an object which allows access to the grouped matches as a sequence. ...
    (comp.lang.python)
  • Re: macros
    ... (:method ((foo foo) ... (baz baz)) ... in Anonymous C Lisper's post (bar bar)" ... latter so you know that this is actually the generic function you want). ...
    (comp.lang.lisp)
  • Re: creating several rows with one insert?
    ... Is there some clever way to cause this to happen in SQL, ... SQL> create table t1as select 'foo' from dual ... union all select 'bar' from dual union all select 'baz' from dual; ...
    (comp.databases.oracle.misc)

Loading