I could not find the problem, but I just copied the contents of the xml into another file and this then worked.
XML not filtering out results from file in Windows Phone
-
07-07-2023 - |
質問
This is the sample XML that I have got:
<ArrayOfService >
<Service z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<primaryUrl>http://www.buses.co.uk/1A</primaryUrl>
<relativePosition>2</relativePosition>
<serviceDescription>Whitehawk - County Hospital - City Centre - Hove - Portslade - Mile Oak</serviceDescription>
<serviceId>1150</serviceId>
<serviceName>1A</serviceName>
<serviceNotes />
<serviceText>Whitehawk - Mile Oak</serviceText>
<serviceUrls />
</Service>
</ArrayOfService>
This is the code:
XDocument loadedData = XDocument.Load("services.xml");
//XNamespace ns = "http://schemas.datacontract.org/2004/07/BusExpress.ClassLibrary";
var list = (from item in loadedData.Descendants("ArrayOfService").Descendants("Service")
where (string)item.Element("serviceName") == "1A"
select (string)item.Element("serviceId")).FirstOrDefault();
The result is coming out as null, why is this?
解決 2
他のヒント
loadedData.Descendants("ArrayOfService")
should be loadedData.Root
See XDocument.Root (MSDN) for details.
所属していません StackOverflow