Getting NULL in XML attribute [Resolved]

Posted by Self-Innovator under XML on 4/17/2016 | Points: 10 | Views : 274 | Status : [Member] | Replies : 1
Hi i'm getting the xml values as null kinldy help.

public logistics GetGeneralInfo(int StoreId)
{
var storeInfoWebService = new UATStoreReportServiceReference.oraclemdb1SoapClient("oraclemdb1Soap");
var logisticsInfoFromService = storeInfoWebService.GetLogistics(StoreId.ToString());
XmlSerializer serializer = new XmlSerializer(typeof(logistics));
StringReader rdr = new StringReader(logisticsInfoFromService);
logistics resultingMessage = (logistics)serializer.Deserialize(rdr);
return resultingMessage;

}


This is my XML string coming in variable logisticsInfoFromService as

<results>
<response mode="all" value=""/>
<logistics>
<freight
rdc1="01 - HARVARD"
rdc2="01 - HARVARD"
freightrate="0 %"
offshoredelivery="Y"
stratcode="Y"
multipledelivery="N"
palletized="N"
totesshipped="0"
totesreturned="0"
toteslastdate="5/30/2001 12:00:00 AM"
containersshipped="0"
containersreturned="0"
containerslastdate="5/30/2001 12:00:00 AM"/>
<routes/>
</logistics>
</results>


I'm gettting the values for freightrate and OffshreDelivery as NULL

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Rajnilari2015 on: 4/18/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Try this (I am using XDoc)

using System;

using System.Xml.Linq;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
XDocument doc = XDocument.Load(@"input.xml");

foreach (var element in doc.Descendants("freight"))
{
Console.WriteLine("{0} = {1}", "rdc1", element.Attribute("rdc1").Value);
Console.WriteLine("{0} = {1}", "rdc2", element.Attribute("rdc2").Value);
Console.WriteLine("{0} = {1}", "freightrate", element.Attribute("freightrate").Value);
Console.WriteLine("{0} = {1}", "offshoredelivery", element.Attribute("offshoredelivery").Value);
Console.WriteLine("{0} = {1}", "stratcode", element.Attribute("stratcode").Value);
Console.WriteLine("{0} = {1}", "multipledelivery", element.Attribute("multipledelivery").Value);
Console.WriteLine("{0} = {1}", "palletized", element.Attribute("palletized").Value);
Console.WriteLine("{0} = {1}", "totesshipped", element.Attribute("totesshipped").Value);
Console.WriteLine("{0} = {1}", "totesreturned", element.Attribute("totesreturned").Value);
Console.WriteLine("{0} = {1}", "toteslastdate", element.Attribute("toteslastdate").Value);
Console.WriteLine("{0} = {1}", "containersshipped", element.Attribute("containersshipped").Value);
Console.WriteLine("{0} = {1}", "containersreturned", element.Attribute("containersreturned").Value);
Console.WriteLine("{0} = {1}", "containerslastdate", element.Attribute("containerslastdate").Value);
}

Console.ReadKey();
}
}
}


Result

rdc1  =  01 - HARVARD

rdc2 = 01 - HARVARD
freightrate = 0 %
offshoredelivery = Y
stratcode = Y
multipledelivery = N
palletized = N
totesshipped = 0
totesreturned = 0
toteslastdate = 5/30/2001 12:00:00 AM
containersshipped = 0
containersreturned = 0
containerslastdate = 5/30/2001 12:00:00 AM


--
Thanks & Regards,
RNA Team

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response