0

Am using DocumentBuilderFactory to read an XML file and write the same file with different file name. Here's my code :

                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                Document dom = db.parse(new InputSource("internal.xml"));

                TransformerFactory transformerFactory = TransformerFactory.newInstance();
                Transformer transformer = transformerFactory.newTransformer();
                DOMSource source = new DOMSource(dom);
                StreamResult result = new StreamResult(new File("newInternal.xml"));
                transformer.transform(source, result);
                System.out.println("File Saved!!!");

But am experiencing error in 'newInternal.xml' file. It's saving with '&lt' , '&gt' in the new file. May I know the issue with the above code ? But it's working fine when I changed the Xml version from 1.1 to 1.0.

4

1 に答える 1

1

あなたのコードは正しいです。正しい XML 構文では、 < と記述します。< と > を表す >を表す。文字は XML 構文自体で使用されるため、これらのエスケープは使用を容易にするために存在します。

この質問には、そのような文字のリストがあります。

于 2012-08-08T04:27:14.883 に答える