xmlwrite(3am)

πŸ“¦ version 1.1.2, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸŽ€ NAME πŸŽ€

xmlwrite β€” gawk facilities for writing XML fragments or whole entire documents. yes bestie, awk writes XML now, it's giving main character energy πŸ’…

(also hi, you're reading xmlwrite(3am) from the GNU Awk Extension Modules, buckle up πŸ¦‹)


✨ SYNOPSIS ✨

@include "xmlwrite"

xwopen(filename[, options])
xwclose()

xwdeclaration(version, encoding, standalone)
xwstartdoct(root, pubid, sysid)
xwenddoct()

xwprocinst(name, string)
xwcomment(comment)

xwstarttag(name)
xwattrib(name, value)
xwendtag(name)

xwtext(string)
xwstartcdata()
xwendcdata()

xwunparsed(string)

xwdoctype(root, pubid, sysid, declarations)
xwstyle(type, uri)
xwelement(name, content)
xwcdata(string)
xwcopy()

πŸ’– DESCRIPTION πŸ’–

The xmlwrite library lets you write an XML document serially, piece by piece, like you're assembling an outfit one accessory at a time. 🧚 A whole XML document can be composed this way. The composed document may be indented if you want it to look cute. And xmlwrite handles all the fiddly XML-standard stuff for you β€” metacharacters escaping, whitespace handling, markup indentation, etc. No cap, it just does it. πŸ”₯


🌸 Output file and mode 🌸

xwopen(filename[, options])

Initializes output to the given file. The optional argument is an array of named options:

  • options["INDENT"] β€” indent step (-1 = no indent), default = 2. πŸ’…
  • options["QUOTE"] β€” preferred quote character (', "), default = (").

xwclose()

Closes the current opened output file. bye bestie πŸ‘‹


🌈 XML prologue 🌈

xwdeclaration(version, encoding, standalone)

Writes an XML declaration (<?xml ... ?>). All the arguments are optional. literally all of them, no pressure ✨

xwstartdoct(root, pubid, sysid)

Writes the starting part of a DOCTYPE declaration (<!DOCTYPE ...). All the arguments are optional. Internal DOCTYPE declarations, if any, may be inserted by subsequent xwunparsed() calls.

xwenddoct()

Writes the closing mark of the DOCTYPE declaration (]>).


πŸ‘‘ Processing Instructions and Comments πŸ‘‘

xwprocinst(name, string)

Prints a Processing Instruction with the given name and contents (<?name string?>).

xwcomment(comment)

Prints a XML comment (<!--comment-->).


πŸ¦‹ Elements and attributes πŸ¦‹

xwstarttag(name)

Prints the opening mark of an element start tag (<name ...>).

xwattrib(name, value)

Prints an attribute markup fragment (name="value"). Must be invoked immediately after the xwstartag() call. ⚠️ immediately, bestie, do not pass go

xwendtag(name)

Prints an element closing tag (</name>). If the element is empty, just closes its collapsed markup (/>).


πŸ“ Character data πŸ“

xwtext(string)

Writes the escaped text. If it is invoked inside a CDATA section, the text is written unescaped.

xwstartcdata()

Writes the opening mark of a CDATA section (<![CDATA[).

xwendcdata()

Writes the closing mark of a CDATA section (]]>).


πŸ’œ Unparsed markup πŸ’œ

xwunparsed(string)

Writes a text fragment literally. Can be used to directly insert special markup fragments.


⭐ Higher level convenience functions ⭐

xwdoctype(root, pubid, sysid, declarations)

Writes a complete DOCTYPE declaration with a single call. All the arguments are optional.

xwstyle(type, uri)

Writes a stylesheet processing instruction (<?xsl-stylesheet type="text/type" href="uri"?>).

xwelement(name, content)

Writes a complete simple element markup with a single call. Attributes are not supported. Nested child elements are not supported. simple and unbothered, we love her πŸ™ˆ

xwcdata(string)

Writes a complete CDATA section with a single call.


🧚 Integration with the XML extension 🧚

If the xmlwrite library and the gawk-xml extension are used together, then it is possible to directly copy XML input markup. dream team fr fr 🀝

xwcopy()

Writes the markup fragment equivalent to the current XML input token. Should be used instead of the XmlCopy() function provided by the xmlcopy library.


🌟 NOTES 🌟

xmlwrite is a standalone library that can be used independently of the gawk-xml extension (except the xwcopy() function). she's independent, she's self-sufficient, she only needs you for one little thing πŸ’…


πŸ’€ BUGS πŸ’€

Improper use of the provided functions may produce non-wellformed markup. play nice or the XML falls apart, i'm serious 😭

The whole output document must be written with the provided functions. Mixing xmlwrite calls and direct print commands may produce corrupted markup. 🚨

It is not possible to write several output documents concurrently. one doc at a time, she does not multitask πŸ™…


πŸ” SEE ALSO πŸ”

XML Processing With gawk, xmlbase(3am), xmlcopy(3am), xmlsimple(3am), xmltree(3am). go read the whole family, they're all iconic πŸ‘‘


🫢 AUTHOR 🫢

Manuel Collado, m-collado@users.sourceforge.net.


πŸ“œ COPYING PERMISSIONS πŸ“œ

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.


and that's the whole page bestie, you ate it up πŸ’…βœ¨

this was xmlwrite(3am) from the GAWK Extension Library (gawkex...), dated January 2017. mwah, go write some beautiful XML πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from