XDocument containing namespaces

Try this, works for me XNamespace nsSys = “http://schemas.microsoft.com/2004/06/windows/eventlog/system”; XElement xEl2 = xDoc.Element(nsSys + “System”); XElement xEl3 = xEl2.Element(nsSys + “Correlation”); XAttribute xAtt1 = xEl3.Attribute(“ActivityID”); String sValue = xAtt1.Value; You need to use Namespaces. Full source for trial public static void Main() { XElement xDoc = XElement.Parse( @”<E2ETraceEvent xmlns=””http://schemas.microsoft.com/2004/06/E2ETraceEvent””> <System xmlns=””http://schemas.microsoft.com/2004/06/windows/eventlog/system””> <EventID>589828</EventID> <Type>3</Type> <SubType Name=””Information””>0</SubType> … Read more

What are XML namespaces for?

They’re for allowing multiple markup languages to be combined, without having to worry about conflicts of element and attribute names. For example, look at any bit of XSLT code, and then think what would happen if you didn’t use namespaces and were trying to write an XSLT where the output has to contain “template”, “for-each”, … Read more

What does elementFormDefault do in XSD?

ElementFormDefault has nothing to do with namespace of the types in the schema, it’s about the namespaces of the elements in XML documents which comply with the schema. Here’s the relevent section of the spec: Element Declaration Schema Component Property {target namespace} Representation If form is present and its ·actual value· is qualified, or if … Read more

xmlns, xmlns:xsi, xsi:schemaLocation, and targetNamespace?

Namespace related attributes in XML and XML Schema (XSD) xmlns is part of the W3C Namespaces in XML Recommendation: The prefix xmlns is used only to declare namespace bindings and is by definition bound to the namespace name http://www.w3.org/2000/xmlns/. In your example, it declares that http://maven.apache.org/POM/4.0.0 is the default namespace for the elements in your … Read more

Use Linq to Xml with Xml namespaces

LINQ to XML methods like Descendants and Element take an XName as an argument. There is a conversion from string to XName that is happening automatically for you. You can fix this by adding an XNamespace before the strings in your Descendants and Element calls. Watch out because you have 2 different namespaces at work. … Read more

What does “xmlns” in XML mean?

It means XML namespace. Basically, every element (or attribute) in XML belongs to a namespace, a way of “qualifying” the name of the element. Imagine you and I both invent our own XML. You invent XML to describe people, I invent mine to describe cities. Both of us include an element called name. Yours refers … Read more