Class XMLReader

java.lang.Object
net.simplace.ui.xmleditorkit.XMLReader

public class XMLReader extends Object
Parses XML with the DOM parser and inserts it into an XMLDocument as nested tag elements with styled brackets, names, attributes, text and comments (singleton).
Author:
Stanislav Lapitsky
  • Method Details

    • getInstance

      public static XMLReader getInstance()
      Returns:
      the singleton instance
    • read

      public void read(InputStream is, Document d, int pos) throws IOException, BadLocationException
      Parses the XML and inserts it at the position; into an empty document including the XML declaration, otherwise only the root element. User changes are switched off while inserting.
      Parameters:
      is - the XML stream
      d - the document; other documents than XMLDocument are ignored
      pos - the insert position
      Throws:
      IOException - if the XML cannot be read or parsed (the stack trace is printed)
      BadLocationException - if the position is invalid
    • writeNode

      public int writeNode(Document doc, Node node, int pos, ArrayList<DefaultStyledDocument.ElementSpec> specs) throws BadLocationException
      Appends the element specs for a node and (recursively) its children: a tag element with start row, attributes, child elements, text and comment rows and end row. Nodes without children are written as <name .../>.
      Parameters:
      doc - the document
      node - the DOM node (document or element)
      pos - the start position
      specs - the list the element specs are appended to
      Returns:
      always 0, since the position is not advanced for element specs
      Throws:
      BadLocationException - not thrown
    • writeNodeOld

      @Deprecated public int writeNodeOld(Document doc, Element node, int pos) throws BadLocationException
      Deprecated.
      not used
      Old variant inserting the element as styled text without tag structure (not used).

      Note: the end tag is written as <name/> instead of </name>.

      Parameters:
      doc - the document
      node - the DOM element
      pos - the insert position
      Returns:
      number of inserted characters
      Throws:
      BadLocationException - if the position is invalid