2

i have some problem with deserialization some of xml

 <?xml version="1.0" encoding="utf-8"?>
 <Group>
  <GroupName>.NET</GroupName>2345
 </Group>
 <!-- ID: [123] -->

How can i get comment(need to get ID) from this xml.

Implement IXmlSerializer it's would be so huge. any ideas how to do in a different way?

if this comment could be between tag - it's not be a problem use XmlAttributeOverrides but it's not.

This is start of processes:

    public object XmlFromStream(HttpWebResponse resp, Type type)
    {
        XmlSerializer xmlSerializer;
        StreamReader responseStream = null;
        try
        {
            xmlSerializer = new XmlSerializer(type);
            Encoding enc = System.Text.Encoding.UTF8;
            responseStream = new StreamReader(resp.GetResponseStream(), enc);
            object objectFromXml = xmlSerializer.Deserialize(responseStream);
            return objectFromXml;
        }
        catch (Exception Ex)
        {
            throw Ex;
        }
        finally
        {
            if (responseStream != null) responseStream.Close();
        }
    }

please show what is next.

ThanX.

AleksP
  • 1,244
  • 2
  • 12
  • 18

1 Answers1

4

The document has only a single root/document element, but it also has other nodes. Using Linq2Xml, you can fish it out like this:

 var doc = XDocument.Parse(docStr);
 var commentValue = doc.Nodes().OfType<XComment>().First().Value;
spender
  • 117,338
  • 33
  • 229
  • 351
  • How about full example. – AleksP Oct 13 '14 at 13:56
  • 1
    @AleksP : A reminder of your question: "How can i get comment". I've gone beyond that by providing the *value* of the comment. Isn't this a full example? If you have your document in a string call `docStr`, then what else could you possibly need? I'm not going to provide a compilable solution file for you. If you need more info, perhaps it might serve you better to ask a better question... – spender Oct 13 '14 at 14:21