Package net.sf.saxon.ma.json

## Class JsonHandlerXML

- java.lang.Object
- - net.sf.saxon.ma.json.JsonHandler
  - - net.sf.saxon.ma.json.JsonHandlerXML

-     public class JsonHandlerXML
      extends JsonHandler

  Handler to generate an XML representation of JSON from a series of events

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static java.lang.String` | `PREFIX` |
    `java.util.HashMap<java.lang.String,​SchemaType>` | `types` |
    `boolean` | `validate` |

    - ### Fields inherited from class net.sf.saxon.ma.json.JsonHandler

      `charChecker, escape`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `JsonHandlerXML​(XPathContext context, java.lang.String staticBaseUri, int flags)` | Make the handler to construct the XML tree representation for JSON

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `endArray()` | Close the current array
    `void` | `endMap()` | Close the current object/map
    `Item` | `getResult()` | Return the complete parsed result
    `protected void` | `markAsEscaped​(java.lang.CharSequence escaped, boolean isKey)` |
    `boolean` | `setKey​(java.lang.String unEscaped, java.lang.String reEscaped)` | Set the key to be written for the next entry in an object/map
    `void` | `setType​(java.lang.String name, SchemaType st)` | Record a SchemaType for a particular name
    `void` | `startArray()` | Open a new array
    `void` | `startMap()` | Start a new object/map
    `void` | `writeBoolean​(boolean value)` | Write a boolean value
    `void` | `writeNull()` | Write a null value
    `void` | `writeNumeric​(java.lang.String asString, double asDouble)` | Write a numeric value
    `void` | `writeString​(java.lang.String val)` | Write a string value

    - ### Methods inherited from class net.sf.saxon.ma.json.JsonHandler

      `getContext, handleInvalidCharacters, reEscape, setContext, setFallbackFunction`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### validate

          public boolean validate

    - #### PREFIX

          public static final java.lang.String PREFIX

      See Also:
        Constant Field Values

    - #### types

          public java.util.HashMap<java.lang.String,​SchemaType> types

  - ### Constructor Detail

    - #### JsonHandlerXML

          public JsonHandlerXML​(XPathContext context,
                                java.lang.String staticBaseUri,
                                int flags)
                         throws XPathException

      Make the handler to construct the XML tree representation for JSON
      Parameters:
        `context` - the context in which the result tree is to be built
        `staticBaseUri` - the static base URI, used for the base URI of the constructed tree
        `flags` - flags indicating the chosen options
      Throws:
        `XPathException` - if initialization fails, for example because of problems loading the schema

  - ### Method Detail

    - #### setType

          public void setType​(java.lang.String name,
                              SchemaType st)

      Record a SchemaType for a particular name
      Parameters:
        `name` - the name to be used for the type, e.g. "arrayType"
        `st` - the schema type to be used for typing such entities

    - #### setKey

          public boolean setKey​(java.lang.String unEscaped,
                                java.lang.String reEscaped)

      Set the key to be written for the next entry in an object/map
      Overrides:
        `setKey` in class `JsonHandler`
      Parameters:
        `unEscaped` - the key for the entry (null implies no key) in unescaped form (backslashes, if present, do not signal an escape sequence)
        `reEscaped` - the key for the entry (null implies no key) in reescaped form. In this form special characters are represented as backslash-escaped sequences if the escape option is yes; if escape=no, the reEscaped form is the same as the unEscaped form.
      Returns:
        true if the key is already present in the map, false if it is not

    - #### getResult

          public Item getResult()
                         throws XPathException

      Return the complete parsed result
      Overrides:
        `getResult` in class `JsonHandler`
      Returns:
        the XML document for this JSON
      Throws:
        `XPathException` - if an error occurs downstream

    - #### startArray

          public void startArray()
                          throws XPathException

      Open a new array
      Overrides:
        `startArray` in class `JsonHandler`
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### endArray

          public void endArray()
                        throws XPathException

      Close the current array
      Overrides:
        `endArray` in class `JsonHandler`
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### startMap

          public void startMap()
                        throws XPathException

      Start a new object/map
      Overrides:
        `startMap` in class `JsonHandler`
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### endMap

          public void endMap()
                      throws XPathException

      Close the current object/map
      Overrides:
        `endMap` in class `JsonHandler`
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### writeNumeric

          public void writeNumeric​(java.lang.String asString,
                                   double asDouble)
                            throws XPathException

      Write a numeric value
      Overrides:
        `writeNumeric` in class `JsonHandler`
      Parameters:
        `asString` - the string representation of the value
        `asDouble` - the double representation of the value
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### writeString

          public void writeString​(java.lang.String val)
                           throws XPathException

      Write a string value
      Overrides:
        `writeString` in class `JsonHandler`
      Parameters:
        `val` - the string to be written. This will be in unescaped form if unescaping was requested in the flags, otherwise it may contain JSON escape sequences
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### markAsEscaped

          protected void markAsEscaped​(java.lang.CharSequence escaped,
                                       boolean isKey)
                                throws XPathException

      Overrides:
        `markAsEscaped` in class `JsonHandler`
      Throws:
        `XPathException`

    - #### writeBoolean

          public void writeBoolean​(boolean value)
                            throws XPathException

      Write a boolean value
      Overrides:
        `writeBoolean` in class `JsonHandler`
      Parameters:
        `value` - the boolean value to be written
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### writeNull

          public void writeNull()
                         throws XPathException

      Write a null value
      Overrides:
        `writeNull` in class `JsonHandler`
      Throws:
        `XPathException` - if a dynamic error occurs