Class XMLUtils
- java.lang.Object
- 
- com.ensoftcorp.open.commons.utilities.XMLUtils
 
- 
 public class XMLUtils extends java.lang.ObjectA helper for computing SourceCorrespondence objects from an XML file Creates an annotated DOM tree, adding start and end line numbers to each XML element- Author:
- Ben Holland
 
- 
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringEND_CHARACTER_OFFSET_USER_DATAstatic java.lang.StringEND_COLUMN_NUMBER_USER_DATAstatic java.lang.StringEND_LINE_NUMBER_CHARACTER_OFFSET_USER_DATAstatic java.lang.StringEND_LINE_NUMBER_USER_DATAstatic java.lang.StringSTART_CHARACTER_OFFSET_USER_DATAstatic java.lang.StringSTART_COLUMN_NUMBER_USER_DATAstatic java.lang.StringSTART_LINE_NUMBER_CHARACTER_OFFSET_USER_DATAstatic java.lang.StringSTART_LINE_NUMBER_USER_DATA
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static org.w3c.dom.DocumentgetAnnotatedDOM(java.io.File file)Just a helper wrapper around the getAnnotatedDOM(InputStream inputStream) methodstatic org.w3c.dom.DocumentgetAnnotatedDOM(java.io.InputStream inputStream)Returns an XML DOM Document object that has been annotated with User Data representing the line numbers and byte offsets of elements.static org.w3c.dom.DocumentgetAnnotatedDOM(java.lang.String xmlString)Just a helper wrapper around the getAnnotatedDOM(InputStream inputStream) methodstatic voidprintDOM(org.w3c.dom.Document doc)Prints the DOM Tree to the consolestatic com.ensoftcorp.atlas.core.index.common.SourceCorrespondencexmlElementToSourceCorrespondence(java.io.File file, org.w3c.dom.Element element)Returns a SourceCorrespondence from an element in an annotated DOMstatic com.ensoftcorp.atlas.core.index.common.SourceCorrespondencexmlFileToSourceCorrespondence(java.io.File file)Returns a SourceCorrespondence set to the first line of the XML file from an element in an annotated DOM
 
- 
- 
- 
Field Detail- 
START_LINE_NUMBER_USER_DATApublic static final java.lang.String START_LINE_NUMBER_USER_DATA - See Also:
- Constant Field Values
 
 - 
END_LINE_NUMBER_USER_DATApublic static final java.lang.String END_LINE_NUMBER_USER_DATA - See Also:
- Constant Field Values
 
 - 
START_COLUMN_NUMBER_USER_DATApublic static final java.lang.String START_COLUMN_NUMBER_USER_DATA - See Also:
- Constant Field Values
 
 - 
END_COLUMN_NUMBER_USER_DATApublic static final java.lang.String END_COLUMN_NUMBER_USER_DATA - See Also:
- Constant Field Values
 
 - 
START_CHARACTER_OFFSET_USER_DATApublic static final java.lang.String START_CHARACTER_OFFSET_USER_DATA - See Also:
- Constant Field Values
 
 - 
END_CHARACTER_OFFSET_USER_DATApublic static final java.lang.String END_CHARACTER_OFFSET_USER_DATA - See Also:
- Constant Field Values
 
 - 
START_LINE_NUMBER_CHARACTER_OFFSET_USER_DATApublic static final java.lang.String START_LINE_NUMBER_CHARACTER_OFFSET_USER_DATA - See Also:
- Constant Field Values
 
 - 
END_LINE_NUMBER_CHARACTER_OFFSET_USER_DATApublic static final java.lang.String END_LINE_NUMBER_CHARACTER_OFFSET_USER_DATA - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
xmlElementToSourceCorrespondencepublic static com.ensoftcorp.atlas.core.index.common.SourceCorrespondence xmlElementToSourceCorrespondence(java.io.File file, org.w3c.dom.Element element)Returns a SourceCorrespondence from an element in an annotated DOM- Parameters:
- file-
- element-
- Returns:
 
 - 
xmlFileToSourceCorrespondencepublic static com.ensoftcorp.atlas.core.index.common.SourceCorrespondence xmlFileToSourceCorrespondence(java.io.File file) Returns a SourceCorrespondence set to the first line of the XML file from an element in an annotated DOM- Parameters:
- file-
- leftElement-
- Returns:
 
 - 
printDOMpublic static void printDOM(org.w3c.dom.Document doc) throws javax.xml.transform.TransformerFactoryConfigurationError, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerExceptionPrints the DOM Tree to the console- Parameters:
- doc-
- Throws:
- javax.xml.transform.TransformerFactoryConfigurationError
- javax.xml.transform.TransformerConfigurationException
- javax.xml.transform.TransformerException
 
 - 
getAnnotatedDOMpublic static org.w3c.dom.Document getAnnotatedDOM(java.io.File file) throws java.io.IOException, org.xml.sax.SAXExceptionJust a helper wrapper around the getAnnotatedDOM(InputStream inputStream) method- Throws:
- java.io.IOException
- org.xml.sax.SAXException
 
 - 
getAnnotatedDOMpublic static org.w3c.dom.Document getAnnotatedDOM(java.lang.String xmlString) throws java.io.IOException, org.xml.sax.SAXExceptionJust a helper wrapper around the getAnnotatedDOM(InputStream inputStream) method- Throws:
- java.io.IOException
- org.xml.sax.SAXException
 
 - 
getAnnotatedDOMpublic static org.w3c.dom.Document getAnnotatedDOM(java.io.InputStream inputStream) throws java.io.IOException, org.xml.sax.SAXExceptionReturns an XML DOM Document object that has been annotated with User Data representing the line numbers and byte offsets of elements. User data attribute names are provided as public final strings in this class. Supported: START_LINE_NUMBER_USER_DATA, START_COLUMN_NUMBER_USER_DATA, START_CHARACTER_OFFSET_USER_DATA, END_LINE_NUMBER_USER_DATA, END_COLUMN_NUMBER_USER_DATA, END_CHARACTER_OFFSET_USER_DATA Example: Node node = doc.getElementsByTagName("foo").item(0); System.out.println("Line number: " + node.getUserData(START_LINE_NUMBER_USER_DATA)); Note: This method will close the input stream! This method was inspired by: http://stackoverflow.com/questions/4915422/get-line-number-from-xml-node-java and http://eyalsch.wordpress.com/2010/11/30/xml-dom-2/ and http://stackoverflow.com/questions/1077865/how-do-i-get-the-correct-starting-ending-locations-of-a-xml-tag-with-sax- Throws:
- java.io.IOException
- org.xml.sax.SAXException
 
 
- 
 
-