XML: do child nodes inherit parent’s namespace prefix?

No. Child nodes do not inherit prefixed namespace by default, and explicit prefix addition needed as you mentioned : <foo:child/>. But they do inherit ancestor’s default namespace (the one without prefix), if any : <root xmlns:foo=”…”> <parent xmlns=”bar”> <child/> </parent> </root> <parent> and <child> nodes are in the same namespace which URI is bar.

The prefix ” cannot be redefined from ” to within the same start element tag

You need to indicate that the element Foo is part of the namespace http://schemas.foo.com. Try this: XNamespace xNamespace = “http://schemas.foo.com”; XNamespace xsi = “http://www.w3.org/2001/XMLSchema-instance”; XElement foo = new XElement( xNamespace + “Foo”, new XAttribute(“xmlns”, “http://schemas.foo.com”), new XAttribute(XNamespace.Xmlns + “xsi”, “http://www.w3.org/2001/XMLSchema-instance”), new XAttribute(xsi + “schemaLocation”, “http://schemas.foo.com http://schemas.foo.com/Current/xsd/Foo.xsd”) );

Why are URLs in XML namespaces?

When you ask why a standard is the way it is, there are two possible interpretations of your question: (a) what are the perceived benefits of the design choice that was made, and (b) what was the historical sequence of events that led to this design being adopted over other designs. Clearly, using HTTP-like URIs … Read more

What is the difference between xsd and xsi?

xsd and xsi Similarities Both are XML namespace prefixes, abbreviations for an XML namespace. Both are, as are all namespace prefixes, arbitrarily named; other namespace prefix abbreviations could equally well be used. However, both prefixes are conventional and therefore recommended. (An also-conventional alternative to xsd is xs.) xsd and xsi Differences The xsd (or xs) … Read more

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

cvc-elt.1: Cannot find the declaration of element ‘MyElement’

Your schema is for its target namespace http://www.example.org/Test so it defines an element with name MyElement in that target namespace http://www.example.org/Test. Your instance document however has an element with name MyElement in no namespace. That is why the validating parser tells you it can’t find a declaration for that element, you haven’t provided a schema … Read more

How does XPath deal with XML namespaces?

XPath 1.0/2.0 Defining namespaces in XPath (recommended) XPath itself doesn’t have a way to bind a namespace prefix with a namespace. Such facilities are provided by the hosting library. It is recommended that you use those facilities and define namespace prefixes that can then be used to qualify XML element and attribute names as necessary. … Read more

Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function

You have to add xsl namespace to XmlNamespaceManager: var document = new XmlDocument(); document.Load(…); var nsmgr = new XmlNamespaceManager(document.NameTable); nsmgr.AddNamespace(“xsl”, “http://www.w3.org/1999/XSL/Transform”); var nl = document.SelectNodes(“//xsl:import/@href”, nsmgr);