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 ( ) . getNextSibling ( ) ; assertEquals ( org.w3c.dom.Node.COMMENT_NODE , commentNode.getNodeType ( ) ) ; com.android.ide.common.blame.SourcePosition position = parser.getPosition ( commentNode ) ; assertNotNull ( position ) ; assertEquals ( 6 , position.getStartLine ( ) ) ; assertEquals ( 4 , position.getStartColumn ( ) ) ; assertEquals ( xml.indexOf ( "<!--" ) , position.getStartOffset ( ) ) ; org.w3c.dom.Element button = ( ( org.w3c.dom.Element ) ( document.getElementsByTagName ( "Button" ) . item ( 0 ) ) ) ; com.android.ide.common.blame.SourcePosition buttonPosition = parser.getPosition ( button ) ; assertNotNull ( buttonPosition ) ; assertEquals ( 7 , buttonPosition.getStartLine ( ) ) ; assertEquals ( 4 , buttonPosition.getStartColumn ( ) ) ; }

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" ) ; 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 = com.android.utils.PositionXmlParser.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.ide.common.blame.SourcePosition position = com.android.utils.PositionXmlParser.getPosition ( commentNode ) ; assertNotNull ( position ) ; assertEquals ( 6 , position.getStartLine ( ) ) ; assertEquals ( 4 , position.getStartColumn ( ) ) ; assertEquals ( xml.indexOf ( "<!--" ) , position.getStartOffset ( ) ) ; org.w3c.dom.Element button = ( ( org.w3c.dom.Element ) ( document.getElementsByTagName ( "Button" ) . item ( 0 ) ) ) ; com.android.ide.common.blame.SourcePosition buttonPosition = com.android.utils.PositionXmlParser.getPosition ( button ) ; assertNotNull ( buttonPosition ) ; assertEquals ( 7 , buttonPosition.getStartLine ( ) ) ; assertEquals ( 4 , buttonPosition.getStartColumn ( ) ) ; }