Jump to content

Xml Help In C# (Dot Net Guys)


Recommended Posts

Posted

 

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. 

 

 

replacing ns1 works but ala replace cheyakudadhu .. you have to declare 

 
XNamespace ns = @"http://www.mysol.com/entity";
 
instead of  xDoc.Descendants("Report")   you have to use    xDoc.Descendants(ns + "Report")     and also for attributes  ns +  ani prefix cheyali

 

anyways ideal solution ante kudaradhu le mana agile world lo .. work aithe chalu :)

Posted

replacing ns1 works but ala replace cheyakudadhu .. you have to declare 

 
XNamespace ns = @"http://www.mysol.com/entity";
 
instead of  xDoc.Descendants("Report")   you have to use    xDoc.Descendants(ns + "Report")     and also for attributes  ns +  ani prefix cheyali

 

anyways ideal solution ante kudaradhu le mana agile world lo .. work aithe chalu :)

i am getting the ns1: value...with that being part of the xml body..i am not able to extract attribute values...

but now able to...

lets c if it works from other system

Posted

i am getting the ns1: value...with that being part of the xml body..i am not able to extract attribute values...

but now able to...

lets c if it works from other system

 

if you don't use XNamespace pani cheyadhu.. em results raavu.. first job in 2011 lo pichi lesindhi.. research chesthe namespaces unte different ga handle cheyali ani artham ayyindhi

Posted

if you don't use XNamespace pani cheyadhu.. em results raavu.. first job in 2011 lo pichi lesindhi.. research chesthe namespaces unte different ga handle cheyali ani artham ayyindhi

i agree we need namespace for objects or xml structure.....

 

I am able to get the call or client request in the xml format with namespace....but with ns1: tag...

it gives me null values when i retrieve from attribute...

 

i used namespace now......thanks

Posted

replacing ns1 works but ala replace cheyakudadhu .. you have to declare 

 
XNamespace ns = @"http://www.mysol.com/entity";
 
instead of  xDoc.Descendants("Report")   you have to use    xDoc.Descendants(ns + "Report")     and also for attributes  ns +  ani prefix cheyali

 

anyways ideal solution ante kudaradhu le mana agile world lo .. work aithe chalu :)

 

agreed..and i used ur suggestion...it worked..thanks

×
×
  • Create New...