Understanding Linq To Xml - Descendants return no results

后端 未结 2 491
谎友^
谎友^ 2020-12-01 20:29

I\'m a completly New to Linq2XML as I code to much lines to perform simple things, and in a simple project I wanted to give it a try...

I\'m with this for 2 hours an

相关标签:
2条回答
  • 2020-12-01 21:05
    var result = doc.Descendants("TransactionInformationType");
    

    selects all descendants in the XDocument that have element name "TransactionInformationType" and are in the empty namespace. From you screenshot it seems the element you're trying to select is in the namespace "https://ssl.ditonlinebetalingssystem.dk/remote/payment" though. You need to specify that explicitly:

    XNamespace ns = "https://ssl.ditonlinebetalingssystem.dk/remote/payment";
                                                  ↑↑                      ↑
    var result = doc.Descendants(ns + "TransactionInformationType");
    
    0 讨论(0)
  • 2020-12-01 21:07

    This should solve you isssue (replace the namespace with the right URL):

    XNamespace ns = "https://ssl.ditonline...";
    doc.Descendants(ns + "TransactionInformationType");
    
    0 讨论(0)
提交回复
热议问题