How to parse XML in Bash?

This is really just an explaination of Yuzem’s answer, but I didn’t feel like this much editing should be done to someone else, and comments don’t allow formatting, so… Let’s call that “read_dom” instead of “rdom”, space it out a bit and use longer variables: Okay so it defines a function called read_dom. The first line makes … Read more

understanding position() function in XSLT

Why does it skip the uneven numbers? Because while you were at the / level, you said: which applies templates to all nodes children of the root node, and (due to the built-in template rules) to all of their descendants – including the text nodes that separate the <a> elements. You will get a different result with an input of: … 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: 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 use the standard XPath function string():

What are invalid characters in XML

The only illegal characters are &, < and > (as well as ” or ‘ in attributes, depending on which character is used to delimit the attribute value: attr=”must use &quot; here, ‘ is allowed” and attr=’must use &apos; here, ” is allowed’). They’re escaped using XML entities, in this case you want &amp; for … Read more

How to add a newline (line break) in XML file?

A newline (aka line break or end-of-line, EOL) is special character or character sequence that marks the end of a line of text. The exact codes used vary across operating systems: You can use &#xA; for line feed (LF) or &#xD; for carriage return (CR), and an XML parser will replace it with the respective character when handing off the parsed text to an application. … Read more