Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my response

HTML
<Storerecords>
<name>xxx</name>
<id>1</id>
</Storerecords>
<Storerecords>
<name>test</name>
<id>2</id>
</Storerecords>
<Storerecords>
<name>test1</name>
<id>3</id>
</Storerecords>


What I have tried:

C#
XmlDocument responseXml = new XmlDocument();

           XmlSerializer xmlSerializer = new XmlSerializer(response.ABRPayloadSearchResults.GetType());
           using (MemoryStream xmlStream = new MemoryStream())
           {
               xmlSerializer.Serialize(xmlStream, response.ABRPayloadSearchResults);
               xmlStream.Position = 0;
               //Loads the XML document from the specified string.
               responseXml.Load(xmlStream);
           }

           XDocument xe = XDocument.Parse(responseXml)//getting error here ;
Posted
Updated 21-Oct-19 6:13am
v3
Comments
Afzaal Ahmad Zeeshan 21-Oct-19 4:51am    
Fetching the first 50 records would still need you create a runtime object (deserialize the XML), which as already mentioned in Solution 1 needs a valid XML document.
chandra sekhar 21-Oct-19 12:11pm    
I have updated the XML

1 solution

Your XML is not valid, you can test it here: XML Validation: XML Validation[^]

If you only want to parse XML partly use XmlReader: https://www.dotnetperls.com/xmlreader[^]

Example:
using (XmlReader reader = XmlReader.Create("test.xml"))
{
    try
    {
        while (reader.Read())
        {
            // Start element
            if (reader.IsStartElement())
            {
                Debug.Print(reader.Name);
                reader.Read();
                Debug.Print(reader.Value);
                Debug.Print("");
            }
        }
    }
    catch (System.Exception ex)
    {
        Debug.Print(ex.Message);
    }
}
 
Share this answer
 
v3
Comments
chandra sekhar 21-Oct-19 3:58am    
So do i need to parse the xml?
RickZeeland 21-Oct-19 4:03am    
Not necessarily, if you only want to search something you could do e.g. responseXml.Contains("<asicnumber>");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900