Class XMLReader
java.lang.Object
net.simplace.ui.xmleditorkit.XMLReader
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 Summary
Modifier and TypeMethodDescriptionstatic XMLReadervoidread(InputStream is, Document d, int pos) Parses the XML and inserts it at the position; into an empty document including the XML declaration, otherwise only the root element.intwriteNode(Document doc, Node node, int pos, ArrayList<DefaultStyledDocument.ElementSpec> specs) 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.intwriteNodeOld(Document doc, Element node, int pos) Deprecated.not used
-
Method Details
-
getInstance
- Returns:
- the singleton instance
-
read
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 streamd- the document; other documents thanXMLDocumentare ignoredpos- 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 documentnode- the DOM node (document or element)pos- the start positionspecs- 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 usedOld 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 documentnode- the DOM elementpos- the insert position- Returns:
- number of inserted characters
- Throws:
BadLocationException- if the position is invalid
-