Source:
public void testOneLineComment ( ) throws java.lang.Exception { java.lang.String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + ( ( ( ( ( ( ( ( ( ( ( ( ( "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " android:layout_width=\"match_parent\"\n" ) + " android:layout_height=\"wrap_content\"\n" ) + " android:orientation=\"vertical\" >\n" ) + "\n" ) + " <!-- this is a comment ! -->\n" ) + " <Button\n" ) + " android:id=\"@+id/button1\"\n" ) + " android:layout_width=\"wrap_content\"\n" ) + " android:layout_height=\"wrap_content\"\n" ) + " android:text=\"Button\" />\n" ) + " some text\n" ) + "\n" ) + "</LinearLayout>\n" ) ; com.android.utils.PositionXmlParser parser = new com.android.utils.PositionXmlParser ( ) ; java.io.File file = java.io.File.createTempFile ( "parsertest" , ".xml" ) ; file.deleteOnExit ( ) ; java.io.Writer fw = new java.io.BufferedWriter ( new java.io.FileWriter ( file ) ) ; fw.write ( xml ) ; fw.close ( ) ; org.w3c.dom.Document document = parser.parse ( new java.io.FileInputStream ( file ) ) ; assertNotNull ( document ) ; org.w3c.dom.Element linearLayout = ( ( org.w3c.dom.Element ) ( document.getElementsByTagName ( "LinearLayout" ) . item ( 0 ) ) ) ; assertNotNull ( linearLayout ) ; org.w3c.dom.Node commentNode = linearLayout.getFirstChild ( ) ; assertEquals ( org.w3c.dom.Node.COMMENT_NODE , commentNode.getNodeType ( ) ) ; com.android.utils.PositionXmlParser.Position position = parser.getPosition ( commentNode ) ; assertNotNull ( position ) ; assertEquals ( 6 , position.getLine ( ) ) ; assertEquals ( 4 , position.getColumn ( ) ) ; assertEquals ( xml.indexOf ( "<!--" ) , position.getOffset ( ) ) ; org.w3c.dom.Element button = ( ( org.w3c.dom.Element ) ( document.getElementsByTagName ( "Button" ) . item ( 0 ) ) ) ; com.android.utils.PositionXmlParser.Position buttonPosition = parser.getPosition ( button ) ; assertNotNull ( buttonPosition ) ; assertEquals ( 7 , buttonPosition.getLine ( ) ) ; assertEquals ( 4 , buttonPosition.getColumn ( ) ) ; }

Target:
public void testOneLineComment ( ) throws java.lang.Exception { java.lang.String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + ( ( ( ( ( ( ( ( ( ( ( ( ( "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " android:layout_width=\"match_parent\"\n" ) + " android:layout_height=\"wrap_content\"\n" ) + " android:orientation=\"vertical\" >\n" ) + "\n" ) + " <!-- this is a comment ! -->\n" ) + " <Button\n" ) + " android:id=\"@+id/button1\"\n" ) + " android:layout_width=\"wrap_content\"\n" ) + " android:layout_height=\"wrap_content\"\n" ) + " android:text=\"Button\" />\n" ) + " some text\n" ) + "\n" ) + "</LinearLayout>\n" ) ; com.android.utils.PositionXmlParser parser = new com.android.utils.PositionXmlParser ( ) ; java.io.File file = java.io.File.createTempFile ( "parsertest" , ".xml" ) ; file.deleteOnExit ( ) ; java.io.Writer fw = new java.io.BufferedWriter ( new java.io.FileWriter ( file ) ) ; fw.write ( xml ) ; fw.close ( ) ; org.w3c.dom.Document document = parser.parse ( new java.io.FileInputStream ( file ) ) ; assertNotNull ( document ) ; org.w3c.dom.Element linearLayout = ( ( org.w3c.dom.Element ) ( document.getElementsByTagName ( "LinearLayout" ) . item ( 0 ) ) ) ; assertNotNull ( linearLayout ) ; org.w3c.dom.Node commentNode = linearLayout.getFirstChild ( ) . getNextSibling ( ) ; assertEquals ( org.w3c.dom.Node.COMMENT_NODE , commentNode.getNodeType ( ) ) ; com.android.utils.PositionXmlParser.Position position = parser.getPosition ( commentNode ) ; assertNotNull ( position ) ; assertEquals ( 6 , position.getLine ( ) ) ; assertEquals ( 4 , position.getColumn ( ) ) ; assertEquals ( xml.indexOf ( "<!--" ) , position.getOffset ( ) ) ; org.w3c.dom.Element button = ( ( org.w3c.dom.Element ) ( document.getElementsByTagName ( "Button" ) . item ( 0 ) ) ) ; com.android.utils.PositionXmlParser.Position buttonPosition = parser.getPosition ( button ) ; assertNotNull ( buttonPosition ) ; assertEquals ( 7 , buttonPosition.getLine ( ) ) ; assertEquals ( 4 , buttonPosition.getColumn ( ) ) ; }