Generic XML Parser in Silverlight 3.0

Hi, I am developing an application in Silverlight 3.0, I want to create a common XML parser in it, since every time I call webservice, I get a different XML, I want to make it general in order to get XML in my own C # data structure? Please help me? for example, I get XML like this time
<test>
 <node1></node1>
 <node2></node2>
</test>

and other time

<mytest>
 <application name="XYZ">My Application</application>
 <application name="ABC">My Application</application>
</mytest>

I need a common parser, for example. it creates some tree structure of all XML

+3
source share
2 answers

I found a solution. A generic XML parser works for me.

0
source

.NET XML.

xml,

<TestObject>
    <FirstProperty>SomeValue</FirstProperty>
    <SecondProperty>17</SecondProperty>
</TestObject>

#

[Serializable]
public class TestObject
{
    public string FirstProperty { get; set; }
    public int SecondProperty { get; set; }
}

xml

string xml = @"<TestObject>
                    <FirstProperty>SomeValue</FirstProperty>
                    <SecondProperty>17</SecondProperty>
                </TestObject>";

XmlSerializer serializer = new XmlSerializer(typeof(TestObject));

using (StringReader reader = new StringReader(xml))
{
    using (XmlTextReader xmlReader = new XmlTextReader(reader))
    {
        TestObject obj = serializer.Deserialize(xmlReader) as TestObject;
    }
}
+1

Source: https://habr.com/ru/post/1743805/


All Articles