c# - How to deserialize a tag nested within a text section of another tag? -
how represent structure of following xml further deserialization classes?
<headelement id="1"> text in headelement start <subelement samp="0"> text in subelement </subelement> continue text </headelement>
my current code looks this:
[datacontract] public class claimtext { [datamember, xmlelement(elementname = "claim-ref")] public claimref claimref; // { get; private set; } public void setclaimref(claimref claimref_) { this.claimref = claimref_; } [datamember, xmltext()] public string txt; // { get; private set; } public void settxt(string txt_) { this.txt = txt_; } }
given following xml contents:
<claim id="clm-00016" num="00016"> <claim-text>16. midgate assembly of <claim-ref idref="clm-00015">claim 15</claim-ref>, further comprising second ramp member connected opposite side of midgate panel selectively covering opposite end of pass-through aperture. </claim-text> </claim>
i object in link "claim-ref" present, not entire text: second part of (", further comprising ..."). how whole text?
first of mixing attributes datacontractserializer
, xmlserializer
.
ad rem: in case of mixed elements it's better use xmlserializer
. here structure works xml:
[xmlroot(elementname = "claim")] public class claimtext { [xmlattribute] public string id; [xmlattribute] public string num; [xmlelement(elementname = "claim-text")] public claiminnercontents contents; } public class claiminnercontents { [xmlelement(elementname = "claim-ref", type = typeof(claimref))] [xmltext(type = typeof(string))] public object[] contents; } public class claimref { [xmlattribute] public string idref; [xmltext] public string text; }
claimref
, splitted text sections deserialized contents
array objects.
you can (and should) of course provide statically typed , checked accessors particular elements of array.
Comments
Post a Comment