Understanding Linq To Xml – Descendants return no results

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 + … Read more

Parsing XML using XDocument

I suspect you’re being stumped by the namespace. Try this: XDocument doc = XDocument.Load(“test.xml”); XNamespace ns = “http://ns.adobe.com/xfdf/”; foreach (XElement element in doc.Root .Element(ns + “fields”) .Elements(ns + “field”)) { Console.WriteLine(“Name: {0}; Value: {1}”, (string) element.Attribute(“name”), (string) element.Element(ns + “value”)); } Or to find just the one specific element: XDocument doc = XDocument.Load(“test.xml”); XNamespace ns … Read more

XmlTextReader vs. XDocument

If you’re happy reading everything into memory, use XDocument. It’ll make your life much easier. LINQ to XML is a lovely API. Use an XmlReader (such as XmlTextReader) if you need to handle huge XML files in a streaming fashion, basically. It’s a much more painful API, but it allows streaming (i.e. only dealing with … Read more

C# XDocument Load with multiple roots

XmlReader itself does support reading of xml fragment – i.e. var settings = new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Fragment }; using (var reader = XmlReader.Create(“fragment.xml”, settings)) { // you can work with reader just fine } However XDocument.Load does not support reading of fragmented xml. Quick and dirty way is to wrap the nodes under … Read more

How can I write xml with a namespace and prefix with XElement?

Here is a small example that creates the output you want: using System; using System.Xml.Linq; class Program { static void Main() { XNamespace ci = “http://somewhere.com”; XNamespace ca = “http://somewhereelse.com”; XElement element = new XElement(“root”, new XAttribute(XNamespace.Xmlns + “ci”, ci), new XAttribute(XNamespace.Xmlns + “ca”, ca), new XElement(ci + “field1”, “test”), new XElement(ca + “field2”, “another … Read more

XML file creation using XDocument in C#

LINQ to XML allows this to be much simpler, through three features: You can construct an object without knowing the document it’s part of You can construct an object and provide the children as arguments If an argument is iterable, it will be iterated over So here you can just do: void Main() { List<string> … Read more

Query XDocument with xmlns attribute (namespace)

Why is it a problem when a xml document contains an xmlns attribute? It’s not, if you understand what it means 🙂 Basically you’ve applied a default namespace URI of “http://schemas.microsoft.com/developer/msbuild/2003” to all elements. So when querying, you need to specify that namespace too. Fortunately, LINQ to XML makes that really simple: XNamespace ns = … Read more

techhipbettruvabetnorabahisbahis forumu