@include "xmlsimple" parentpath = XmlParent(path) test = XmlMatch(path) scopepath = XmlMatchScope(path) ancestorpath = XmlMatchAttr(path, name, value, mode) XmlGrep()
The xmlsimple library facilitates writing scripts based on the gawk-xml extension. It is an alternative to the xmllib library. A key difference is that $0 is not changed, so xmlsimple is compatible with awk code that relies on the gawk-xml core interface.
Short token variable names
To shorten simple scripts, xmlsimple provides two-letter named variables that duplicate predefined token-related core variables:
Equivalent to XMLDECLARATION.
Equivalent to XMLSTARTDOCT.
Equivalent to XMLENDDOCT.
Equivalent to XMLPROCINST.
Equivalent to XMLSTARTELEM.
Equivalent to XMLENDELEM.
Equivalent to XMLCHARDATA.
Equivalent to XMLSTARTCDATA.
Equivalent to XMLENDCDATA.
Equivalent to XMLCOMMENT.
Equivalent to XMLUNPARSED.
Equivalent to XMLENDDOCUMENT.
Collecting character data
Character data items between element tags are automatically collected in a single CHARDATA variable. This feature simplifies processing text data interspersed with comments, processing instructions or CDATA markup.
Available at every XMLSTARTELEMENT or XMLENDELEMENT token. Contains all the character data since the previous start- or end-element tag.
The XMLTRIM mode variable controls whether whitespace in the CHARDATA variable is automatically trimmed or not. Possible values are:
- XMLTRIM = 0
Keep all whitespace
- XMLTRIM = 1 (default)
Discard leading and trailing whitespace, and collapse contiguous whitespace characters into a single space char.
- XMLTRIM = -1
Just collapse contiguous whitespace characters into a single space char. Keeps the collapsed leading or trailing whitespace.
Record ancestors information
The ATTR array variable automatically keeps the attributes of every ancestor of the current element, and of the element itself.
Contains the value of the specified attribute of the ancestor element at the given path.
While processing a
ATTR["/books/book@on-loan"] contains the name of the book loaner.
If invoked at the XMLSTARTELEM event, causes the whole element subtree to be copied to the output.
The xmlsimple library includes both the xmlbase and xmlcopy libraries. Their functionality is implicitly available.
The path related functions only operate on elements. Comments, processing instructions or CDATA sections are not taken into account.
XmlGrep() cannot be used to copy tokens outside the root element (XML prologue or epilogue).
XML Processing With gawk, xmlbase(3am), xmlcopy(3am), xmltree(3am), xmlwrite(3am).
Manuel Collado, firstname.lastname@example.org.
Copyright (C) 2017, Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this manual page provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual page under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual page into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation.