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

How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?

How to link an XSD to an XML document depends upon whether the XML document is using namespaces or not… Without namespaces Use xsi:noNamespaceSchemaLocation to provide a hint as to the XSD to be used: XML <root xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”example.xsd”> <!– … –> </root> XSD <xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”> <xsd:element name=”root”> <!– … –> </xsd:element> </xsd:schema> With namespaces … 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

XPath query to get nth instance of an element

This is a FAQ: //somexpression[$N] means “Find every node selected by //somexpression that is the $Nth child of its parent”. What you want is: (//input[@id=”search_query”])[2] Remember: The [] operator has higher precedence (priority) than the // abbreviation.

Auto line-wrapping in SVG text

Text wrapping is not part of SVG1.1, the currently implemented spec. In case you are going to use your SVG graphic on the Web, you can embed HTML inside SVG via the <foreignObject/> element. Example: <svg …> <switch> <foreignObject x=”20″ y=”90″ width=”150″ height=”200″> <p xmlns=”http://www.w3.org/1999/xhtml”>Text goes here</p> </foreignObject> <text x=”20″ y=”20″>Your SVG viewer cannot display … Read more

How to execute XPath one-liners from shell?

You should try these tools : xmlstarlet : can edit, select, transform… Not installed by default, xpath1 xmllint : often installed by default with libxml2-utils, xpath1 (check my wrapper to have –xpath switch on very old releases and newlines delimited output (v < 2.9.9) xpath : installed via perl’s module XML::XPath, xpath1 xml_grep : installed … Read more

What does in XML mean?

CDATA stands for Character Data and it means that the data in between these strings includes data that could be interpreted as XML markup, but should not be. The key differences between CDATA and comments are: As Richard points out, CDATA is still part of the document, while a comment is not. In CDATA you … Read more