This seems something that should be easy and not uncommon... but hours
of searching have yielded nothing!
I am using XmlSerializer to map some XML (not defined by me) into some
class objects (defined by me). And it is working great for most cases.
Just have one more to handle...
One of the leaf nodes of the tree I build is "ci"... typically looks
like this:
<ci>someIdentifier</ci>
To implement that, my class "ci" has the following:
[XmlText(typeof(string))]
public string TheString = null;
Works great.
However, the XML allows for some presentation nodes inside <ci>. For
example:
<ci><msub><mi>T</mi><mn>0</mn></msub></ci> ==> gives you T with
subscript 0
<ci>°C</ci> ==> gives you the typical way you'd write degrees
Celsius
To me, that presentation stuff is irrelevant. Its just a fancy
identifier. But I need to capture that string between the <ci> and the
</ci>, use it like I use "someIdentifier", and be able to serialize it
back out.
Unfortunately, that does NOT currently work... the XmlSerializer turns
the first case into a bunch of unrecognized nodes which vanish and
TheString ends up empty... and the XmlSerializer throws an exception on
the second case, because the entity "deg" is not known.
What I need is the ability to say "TheString holds all the raw XML
between <ci> and </ci>". So, something like:
[XmlXml()]
public string TheString = null;
[XmlRaw()]
public string TheString = null;
or perhaps to tell XmlText that the type of this thing is PCDATA:
[XmlText(typeof(PCDATA))]
public string TheString = null;
None of those are the answer; but I'm thinking the answer might be
similarly simple.
Suggestions?
Thanks.