MegaPowerRockstar Posted August 11, 2014 Report Posted August 11, 2014 Hi Guys, Need help in getting results from the xml tag. I have the below xml formatted data. How can i extract the values of Name, Description, Created, FileName values from the below xml structure to an object. <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ns1:dataset xmlns:ns1="http://www.mysol.com/entity"> <ns1:Report Name="SalesOctober08" Description="Monthly Sales Analysis Rpt 1" Created="01/01/2008" FileName="Sales_rpt_2008" /> <ns1:Report Name="SalesOctober09" Description="Monthly Sales Analysis Rpt 2" Created="01/01/2009" FileName="Sales_rpt_2009" /> </ns1:dataset> Thanks.
Spartan Posted August 11, 2014 Report Posted August 11, 2014 http://msdn.microsoft.com/en-us/library/windows/desktop/ms699317%28v=vs.100%29.aspx
MegaPowerRockstar Posted August 11, 2014 Author Report Posted August 11, 2014 Open XML file with MS Excel man... i need programmatially.... i need to extract the values and tie it to an object
Spartan Posted August 11, 2014 Report Posted August 11, 2014 i need programmatially.... i need to extract the values and tie it to an object check that link..
karna11 Posted August 11, 2014 Report Posted August 11, 2014 System.Xml.XmlDocument myxmldoc = newSystem.Xml.XmlDocument(); myxmldoc.Load("MyXMLFile1.xml");//if you have the xmlfile outside the solution explorer insert the full path to it System.Xml.XmlNodeList mynodes = myxmldoc.SelectNodes("dataset/add what ever attributes u need"); foreach (System.Xml.XmlNode mynode in mynodes) {MessageBox.Show(mynode.InnerText); } 1
puli_keka Posted August 11, 2014 Report Posted August 11, 2014 Check XElement and XDocument tutorials in dotnetperls etc... It's very Easy to extract attributes and tag values
MegaPowerRockstar Posted August 11, 2014 Author Report Posted August 11, 2014 System.Xml.XmlDocument myxmldoc = newSystem.Xml.XmlDocument(); myxmldoc.Load("MyXMLFile1.xml");//if you have the xmlfile outside the solution explorer insert the full path to it System.Xml.XmlNodeList mynodes = myxmldoc.SelectNodes("[font='Segoe UI']dataset[/font]/add what ever attributes u need"); foreach (System.Xml.XmlNode mynode in mynodes) { MessageBox.Show(mynode.InnerText); } Thanks.... What if I the XML content in xelement.... .? I tried this it had null... Should I ignore ns1???
MegaPowerRockstar Posted August 11, 2014 Author Report Posted August 11, 2014 Check XElement and XDocument tutorials in dotnetperls etc... It's very Easy to extract attributes and tag values I have done it before for XML message of type <Name> john<\Name> But not of type <person><name = "john"<\person> Anyways I will check the sites
puli_keka Posted August 11, 2014 Report Posted August 11, 2014 I have done it before for XML message of type <Name> john<\Name> But not of type <person><name = "john"<\person> Anyways I will check the sites even to get John its very easy with XElement man ... check it out
ChampakDas Posted August 11, 2014 Report Posted August 11, 2014 </person> xmlelement ki parse method untadi use that and iterate through name.descedants aa name check chesko ganthe :5_2_108: I have done it before for XML message of type <Name> john<\Name> But not of type <person><name = "john"<\person> Anyways I will check the sites
MegaPowerRockstar Posted August 12, 2014 Author Report Posted August 12, 2014 thanks for your help guys... I found the solution... Since my request had "ns1:" in the beginning of the xml tag.....i had to convert to string and then replcase all "ns1:" with blanks and then used parse .... string frmTReq = "<ns1:dataset xmlns:ns1="http://www.mysol.com/entity"> <ns1:Report Name="SalesOctober08" Description="Monthly Sales Analysis Rpt 1" Created="01/01/2008" FileName="Sales_rpt_2008" /> <ns1:Report Name="SalesOctober09" Description="Monthly Sales Analysis Rpt 2" Created="01/01/2009" FileName="Sales_rpt_2009" /> </ns1:dataset>"; List<Person> personList = new list<Person>(); XDocument xDoc = XDocument.Parse(frmTReq); foreach (var node in xDoc.Descendants("Report")) { Person pr = new Person() { Name= node.Attribute("Name").Value, Description= node.Attribute("Description").Value, Created= node.Attribute("Created").Value, FileName= node.Attribute("FileName").Value }; personlist.add(pr); } This helped my scneriao... thanks guys.
Recommended Posts