开发者

Deserialize unknown section into List or Dictionary

开发者 https://www.devze.com 2023-04-07 07:15 出处:网络
I have the following XML file: <Error>0</Error> <Description>1</Description> <Document>

I have the following XML file:

<Error>0</Error>
<Description>1</Description>
<Document>
  <ObjectID>06098INF1761320</ObjectID>
  <ced>109340336</ced>
  <abstract>DAVID STEVENSON</abstract>
  <ced_a />
  <NAM_REC />
  <ced_ap2 />
</Document>

So I deserialize it on C# (4.0) with this objects structure:

        [XmlElement("Error")]
        public string Error { get; set; }

        [XmlElement("Description")]
        public string Description { get; set; }

        [XmlElement("Document")]
        public List<EDocument> LstDocument { get; set; }

So here's my issue: the element "Document" has unknown sub-elements: ObjectID, ced, etc., is there a way that I can deserialize those unknows elements into a List, Array, Dictionary or something to iterate with (something like this, it DOESN'T have to be exactly like this, I'm just guessing):

object.LstDocument[0].ListDocument.name; //to get the name
object.LstDocument[0].ListDocument.value; //to get the value

Any help would be appreciated.

EDIT 1:

To add some extra clarification to my question: The child nodes under "Document" element are unknown because they are variable, with this I mean that at a moment I could have "ObjectID" and "ced", i开发者_JAVA百科n other moment they could be "ced","ABC", etc. I'm not sure which elements came there as child nodes, all I know is that they are elements (not attributes) and that they don't have any child-nodes inside them.

0

精彩评论

暂无评论...
验证码 换一张
取 消