2

I have this XML document:

<?xml version="1.0" encoding="utf-8"?>
<directoryresponse xmlns="https://www.sisow.nl/Sisow/REST" version="1.0.0">
  <directory>
    <issuer>
      <issuerid>01</issuerid>
      <issuername>ABN Amro Bank</issuername>
    </issuer>
    <issuer>
      <issuerid>02</issuerid>
      <issuername>ASN Bank</issuername>
    </issuer>
  </directory>
</directoryresponse>

And this does not work:

var banks = doc.Descendants("issuer").Select(x => 
    new Bank(Convert.ToInt32(x.Element("issuerid").Value), x.Element("issuername").Value)).ToList();

But when I manual remove the directoryresponse xml namespace xmlns="https://www.sisow.nl/Sisow/REST" it works! The namespace url is a 404. So why doesn't the xdoc ignore the namespace if it's a 404?

This also does not work: var banks = doc.Elements().Where(e => e.Name.LocalName == "issuer" ).Select(...

The main question is: how can I modify my code so that it ignores the 404 namespace?

1 Answer 1

4

The URL itself is irrelevant here - it's just a token for the namespace, really. I don't believe LINQ to XML will try to fetch it.

However, you need to use it to construct the XName to search for:

XNamespace ns = "https://www.sisow.nl/Sisow/REST";
var banks = doc.Descendants(ns + "issuer")
               .Select(x => new Bank((int) x.Element(ns + "issuerid"),
                                     (string) x.Element(ns + "issuername"))
               .ToList();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.