Puds32
asked on
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:C ontactPoin t:outcome: success"/>
<ns3:Child>
<ns3:DSI subdomain="UID" scope="NAT">02MZX8XM2BWH02 33</ns3:DS I>
<ns3:Summary shielded="false">
<ns3:ChildName FamilyNameFirstFlag="false ">
<ns1:FamilyName>LEWIS</ns1 :FamilyNam e>
<ns1:GivenName1>Jallie</ns 1:GivenNam e1>
</ns3:ChildName>
<ns3:DateOfBirth>1996-09-0 5</ns3:Dat eOfBirth>
<ns3:Gender>female</ns3:Ge nder>
<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
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:C
<ns3:Child>
<ns3:DSI subdomain="UID" scope="NAT">02MZX8XM2BWH02
<ns3:Summary shielded="false">
<ns3:ChildName FamilyNameFirstFlag="false
<ns1:FamilyName>LEWIS</ns1
<ns1:GivenName1>Jallie</ns
</ns3:ChildName>
<ns3:DateOfBirth>1996-09-0
<ns3:Gender>female</ns3:Ge
<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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi
From the ns3:Child node and all within - thanks for your help
From the ns3:Child node and all within - thanks for your help
Can you post the web method declaration?
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
ASKER
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.Na meTable);
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("soapen v", "http://schemas.xmlsoap.org/soap/envelope/");
XmlNode nFamilyName = doc.SelectSingleNode("/soa penv:Envel ope/soapen v:Body/ns3 :SearchRes ponse/ns3: Child/ns3: Summary/
ns3:ChildName/ns1:FamilyNa me", nmMan);
if (nFamilyName != null)
{
TextBox2.Text = nFamilyName.InnerXml;
}
}
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.Na
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("soapen
XmlNode nFamilyName = doc.SelectSingleNode("/soa
ns3:ChildName/ns1:FamilyNa
if (nFamilyName != null)
{
TextBox2.Text = nFamilyName.InnerXml;
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.GetElementsByTagNam e("ns3:Ser viceProvis ions");
foreach (XmlNode root in elemList)
{
if (root.HasChildNodes)
{
int iNode;
int iNodes;
iNodes = root.ChildNodes.Count;
TextBox1.Text = TextBox1.Text + root.ChildNodes.Count.ToSt ring();
for (iNode = 0; iNode < iNodes; iNode++)
{
TextBox1.Text = TextBox1.Text + "\nl" + root.ChildNodes[iNode].Nam e + " "
+ root.ChildNodes[iNode].Inn erText;
}
}
}
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
I have decided on a cobination of XPath and XMLDataDocument.
Code snippet:
XmlDataDocument xmlDoc = new XmlDataDocument();
xmlDoc.Load("c:\\TEST6.xml
XmlNodeList elemList = xmlDoc.GetElementsByTagNam
foreach (XmlNode root in elemList)
{
if (root.HasChildNodes)
{
int iNode;
int iNodes;
iNodes = root.ChildNodes.Count;
TextBox1.Text = TextBox1.Text + root.ChildNodes.Count.ToSt
for (iNode = 0; iNode < iNodes; iNode++)
{
TextBox1.Text = TextBox1.Text + "\nl" + root.ChildNodes[iNode].Nam
+ root.ChildNodes[iNode].Inn
}
}
}
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
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