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

Getting attribute using XPath

How could I get the value of lang (where lang=eng in book title), for the first element? Use: /*/book[1]/title/@lang This means: Select the lang attribute of the title element that is a child of the first book child of the top element of the XML document. To get just the string value of this attribute … Read more

Unable to completely parse XML in PowerShell

XML is a structured text format. It knows nothing about “folders”. What you see in your screenshots is just how the the data is rendered by program you use for displaying it. Anyway, the best approach to get what you want is using SelectNodes() with an XPath expression. As usual. [xml]$xml = Get-Content ‘X:\folder\my.xml’ $xml.SelectNodes(‘//Product/Item[@Class=”Patch”]’) … Read more

XML Schema minOccurs / maxOccurs default values

The default values for minOccurs and maxOccurs are 1. Thus: <xsd:element minOccurs=”1″ name=”asdf”/> cardinality is [1-1] Note: if you specify only minOccurs attribute, it can’t be greater than 1, because the default value for maxOccurs is 1. <xsd:element minOccurs=”5″ maxOccurs=”2″ name=”asdf”/> invalid <xsd:element maxOccurs=”2″ name=”asdf”/> cardinality is [1-2] Note: if you specify only maxOccurs attribute, … Read more