[page XML Handler] [t1]XML Handler[t1] [section] The xml handler is used to highlight a chunk of xml text. The handler is implemented by the [javadoc hoglet,org.hoglet.handlers.core.XMLHandler,lastid=y /] class and initialized via the [link xml-configured-processor.html]XML Configured Processor[link]. The xml must be well-formed and parseable. You can either provide the xml to highlight as the content of the tag, or (as of version 0.2) you can specify a xml file and an XPath (like, not strictly XPath syntax) expression to identify an element that should be extracted from the file and highlighted. Example: [hoglet] \[xml] <html> <body> <h1>Hello World!</h1> </body> </html> \[xml] [hoglet] (As an aside, it was a real pain to do the xml above because all the < characters have to be replaced with a &lt; character entity!) Becomes: [xml]

Hello World!

[xml] Another example: [hoglet] \[xml hoglet,data/tag-handlers.xml,/tagHandlers/handler@tag:xml \/\] [hoglet] Becomes: [xml hoglet,data/tag-handlers.xml,/tagHandlers/handler@tag:xml /] [t3]Handler Options[t3] The handler supports up to 3 anonymous options. The behaviour of the handler is dependent upon the number of options provided. 3 Options provided In this case: [l] [i]Option 1 is taken to be a [link #shortcuts]shortcut[link] to a url that should be prefixed to Option 2.[i] [i]Option 2 is taken to be a path that should be appended to Option 1. The combination of Option 1 (expanded to get the real url prefix) and Option 2 constitute the url to use. The url should point to a file that contains the xml to use.[i] [i]Option 3 is taken to be a [link #xpaths]XPath[link] that is used to identify an element that should be extracted from the file.[i] [l] Example: [hoglet] \[xml hoglet,data/tag-handlers.xml,/tagHandlers/handler@tag:xml \/\] [hoglet] 2 Options provided In this case: [l] [i]Option 1 is taken to be a url that should point to a file to be retreived. A check is also made to see if Option 1 maps to one of the [link #shortcuts]shortcuts[link] known to the handler, if a match is found then the shortcut url is used instead.[i] [i]Option 2 is taken to be a [link #xpaths]XPath[link] that is used to identify an element that should be extracted from the file.[i] [l] Example, with Option 1 providing the full url: [hoglet] \[xml http://hoglet.sourceforge.net/data/tag-handlers.xml,/tagHandlers/handler@tag:xml \/\] [hoglet] Example, with Option 1 providing a shortcut value to the url: [hoglet] \[xml hoglet,/tagHandlers/handler@tag:xml \/\] [hoglet] 1 Option provided In this case: [l] [i]Option 1 is taken to be a url that should point to a file to be retreived. In this case the entire contents of the file is used. A check is also made to see if Option 1 maps to one of the [link #shortcuts]shortcuts[link] known to the handler, if a match is found then the shortcut url is used instead.[i] [l] Example: [hoglet] \[xml http://hoglet.sourceforge.net/data/tag-handlers.xml \/\] [hoglet] Example, using shortcut: [hoglet] \[xml taghandlers \/\] [hoglet] [t3]URLs[t3] Protocols http, https and file are supported for the urls. If no protocol is explicitly provided then file is assumed. Relative file paths are NOT supported. [t3 xpaths]XPaths[t3] A very small subset of XPath is supported to allow the unique identification of an element within the file. Also, the syntax has been modified slightly to allow for seemless integration with hoglet (i.e. so that extensive escaping isn't required within the hoglet tag). All paths must start with / and thus refer to the root element. Child elements are separated with /. You can refer to an attribute by appending @ after the element name (note: DO NOT use \[) and then providing the attribute name, i.e. myelement@myattribute. To specify an attribute value append : after the attribute name and then the value. Thus: [com]myelement@myattribute:value[com] [t3 shortcuts]Shortcuts[t3] To make referencing urls easier the handler supports shortcuts. This is basically a short name that maps to a url prefix (or a full url). The shortcuts are defined in the init element. The shortcut is defined by using a src element, two attributes id and url are required, the id attribute defines the short name for the shortcut and the url defines the url that it maps to. Example: [hoglet] \[xml hoglet,data/tag-handlers.xml,/tagHandlers/handler@tag:xml/init/src /] [hoglet] There is no limit to the number of shortcuts that can be defined. Shortcut names are case-sensitive. [t3]XML Initialization[t3] The handler is initialized via an init element (see [link xml-configured-processor.html]XML Configured Processor[link] for details). The init element can optionally contain one or more src elements (see [link #shortcuts]shortcuts[link]). It should also contain a templates element. Which in turn should contain a wrapper element that contains some wrapper markup. The value: \[\[VALUE\]\] is replaced in that markup with the processed/highlighted xml. For example: [xml hoglet,data/tag-handlers.xml,/tagHandlers/handler@tag:xml/init/templates/wrapper /] The templates element can also, optionally, contain the following elements (each one is effectively a template which is used to wrap part of the xml thus providing the highlighting): [l] [i]elementNameWrapper - this is used to wrap the element name.[i] [i]attributeNameWrapper - this is used to wrap an attribute name.[i] [i]attributeValueWrapper - this is used to wrap an attribute value.[i] [i]textWrapper - this is used to wrap text content, including a CDATA section.[i] [i]commentWrapper - this is used to wrap a comment.[i] [l] In each of the wrapper templates defined above, they should contain a \[\[VALUE\]\] value, that value will be replaced with the relevant value from the xml file. [/section] [/page]