How do you load this xml file into datagrid

I am trying to load the following file into a datagrid but not getting anywhere
The xml file is as follows, note there is no xsl file:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <ns3:SearchResponse xmlns:ns1="http://www.govtalk.gov.uk/Education/ContactPoint/Common" xmlns:ns2="http://www.govtalk.gov.uk/people/bs7666" xmlns:ns3="http://www.govtalk.gov.uk/Education/ContactPoint/Enquiry">
      <ns3:Status outcome="urn:uk:gov:dcsf:ContactPoint:outcome:success"/>
      <ns3:Child>
        <ns3:DSI subdomain="UID" scope="NAT">02MZX8XM2BWH0233</ns3:DSI>
        <ns3:Summary shielded="false">
          <ns3:ChildName FamilyNameFirstFlag="false">
            <ns1:FamilyName>LEWIS</ns1:FamilyName>
            <ns1:GivenName1>Jallie</ns1:GivenName1>
          </ns3:ChildName>
          <ns3:DateOfBirth>1996-09-05</ns3:DateOfBirth>
          <ns3:Gender>female</ns3:Gender>
          <ns3:AddressInfo>11 GLOUCESTER ROAD, M14 5BZ</ns3:AddressInfo>
          <ns3:ParentInfo>LEWIS Danya</ns3:ParentInfo>
        </ns3:Summary></ns3:Child>
    </ns3:SearchResponse>
  </soapenv:Body>
</soapenv:Envelope>


I am using asp.net 3.5, c#
If any one can help I would be most grateful
Thanks
Puds32Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
Check:
http://www.java2s.com/Code/ASP/XML/ReadxmldataandbindtodatagridinC.htm

By the way your xml looks more like a web service response. You are better off capturing the object from the response and loading that object to the datagrid rather than using the intermidiate xml step.
0
gokujamesCommented:
Did you try Xml datasource that comes with the .NET framework 3.5 as  i am almost near to displaying it without anything other than Xml Datasource.
If you want the exact match , then please use the XPath expression and bind them individually.
Also did you try reading the xml file into a Dataset and then binding them
0
Puds32Author Commented:
Sorry, yes it is a web service response
I have tried using an XML Datasource but I get the error:
"There was an error renering the control.
The data source for gridview with id 'GridView3' did not have any properties or attributes for which to generate columns. Ensure that your data source has content.
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

gokujamesCommented:
by the way , what do you want to display exactly from the webservice response.Because they split to almost 5 related tables when loaded through dataset.So which are the tags you are interested in displaying
0
Puds32Author Commented:
Hi
From the ns3:Child node and all within - thanks for your help
0
Miguel OzSoftware EngineerCommented:
Can you post the web method declaration?
0
Puds32Author Commented:
Sorry for the delay in reply, have been side tracked by other work.

Update - I got some way to an acceptable answer using a dataset  loaded from a text stream, however when the xml structure became more complicated a problem arrose when repeat nested element names ie address, being used as a child for client and for parent, this stopped the automatic creation of the table structure and caused an error, I think I may be going down the wrong road here.

It looks like I need to use either xpath or Linq, does anybody have a view to either preferrence, and if so direct me to a good resource suitable for thickies

As always thanks to everyone for their time
0
Miguel OzSoftware EngineerCommented:
xpath will be the way to go:
msdn.microsoft.com/en-us/library/d271ytdx.aspx
msdn.microsoft.com/en-us/library/system.xml.xmlnode.selectnodes.aspx
http://forums.fanatic.net.nz/index.php?showtopic=17504
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Puds32Author Commented:
Right xpath it is then

In the above xml fragment do I have to create an xmlnamespace manager, if so what would the following code snippit look like

nsmgr.AddNamespace("", "");

and do I have to add all the namespaces to the manager

Thanks
0
Puds32Author Commented:
I am starting to have some success!!
The below hooks out the FamilyName. How can I change it to pull out a FamilyName that is equel to a value ie. FamilyName = 'LEWIS1'

Ta


XmlDocument doc = new XmlDocument();
            doc.Load("c:\\testFile.xml");
            XmlNode root = doc.DocumentElement;

            XmlNamespaceManager nmMan = new XmlNamespaceManager(doc.NameTable);

            nmMan.AddNamespace("ns1", "http://www.govtalk.gov.uk/Education/ContactPoint/Common");
            nmMan.AddNamespace("ns2", "http://www.govtalk.gov.uk/people/bs7666");
            nmMan.AddNamespace("ns3", "http://www.govtalk.gov.uk/Education/ContactPoint/Enquiry");
            nmMan.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");


            XmlNode nFamilyName = doc.SelectSingleNode("/soapenv:Envelope/soapenv:Body/ns3:SearchResponse/ns3:Child/ns3:Summary/
ns3:ChildName/ns1:FamilyName", nmMan);

           
            if (nFamilyName != null)
            {
                TextBox2.Text = nFamilyName.InnerXml;
            }
        }
0
Miguel OzSoftware EngineerCommented:
Replace:
XmlNode nFamilyName = doc.SelectSingleNode("/soapenv:Envelope/soapenv:Body/ns3:SearchResponse/ns3:Child/ns3:Summary/
ns3:ChildName/ns1:FamilyName", nmMan);

with:
XmlNode nFamilyName = doc.SelectSingleNode("/soapenv:Envelope/soapenv:Body/ns3:SearchResponse/ns3:Child/ns3:Summary/
ns3:ChildName/ns1:FamilyName[@ns1:FamilyName='LEWIS1']", nmMan);
0
Puds32Author Commented:
Hi to all
I have decided on a cobination of XPath and XMLDataDocument.
Code snippet:
 XmlDataDocument xmlDoc = new XmlDataDocument();

            xmlDoc.Load("c:\\TEST6.xml");

            XmlNodeList elemList = xmlDoc.GetElementsByTagName("ns3:ServiceProvisions");
           

            foreach (XmlNode root in elemList)
            {
                if (root.HasChildNodes)
                {
                    int iNode;
                    int iNodes;

                    iNodes = root.ChildNodes.Count;
                    TextBox1.Text = TextBox1.Text + root.ChildNodes.Count.ToString();
                    for (iNode = 0; iNode < iNodes; iNode++)
                    {
                        TextBox1.Text = TextBox1.Text + "\nl" + root.ChildNodes[iNode].Name + " "

                            + root.ChildNodes[iNode].InnerText;
                    }
                }
            }


The combination works well and I'm now getting quite proficient so will now close this question.
Thanks as usual for all the help.
Until my next question ...
Puds32
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.