如何使用org.w3c.dom在属性之间添加新行。JAVA中的xml

如何使用org.w3c.dom在属性之间添加新行。JAVA中的xml,java,xml,dom,Java,Xml,Dom,我正在使用JAVA中的org.w3c.dom和javax.xml.parsers创建xml文件。但它给我的结果如下: <rdf:RDF xmlns:esv="http://eresources.nlb.gov.sg/ID/NLBDM/vocab-esv/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:nlbdm="http://eresources.nlb.gov.sg/ID/NLBDM/vocab/" xmlns:owl="http://w

我正在使用JAVA中的org.w3c.dom和javax.xml.parsers创建xml文件。但它给我的结果如下:

<rdf:RDF xmlns:esv="http://eresources.nlb.gov.sg/ID/NLBDM/vocab-esv/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:nlbdm="http://eresources.nlb.gov.sg/ID/NLBDM/vocab/" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
</rdf:RDF>
<rdf:RDF
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:esv="http://eresources.nlb.gov.sg/ID/NLBDM/vocab-esv/"
    xmlns:nlbdm="http://eresources.nlb.gov.sg/ID/NLBDM/vocab/">
</rdf:RDF>

我不知道有哪种序列化XML的工具可以让您对结果的精确布局进行如此大的控制。你为什么在乎?额外的空白可能在视觉上很吸引人,但没有一个正常的XML消费应用程序会根据属性之间的空白量表现出不同的行为


(好吧,我这么说了,但今天早上我注意到另一个问题,那就是试图使用sed或awk处理XML。这超出了我对使用XML的应用程序的定义…

与论坛网站不同,我们不使用“谢谢”或“感谢任何帮助”或签名。顺便说一句,这是“提前感谢”,而不是“提前感谢”。
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();

transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

DOMSource source = new DOMSource(doc);

String tempFileName=file.getName();
tempFileName=tempFileName.substring(0,tempFileName.indexOf("."));

StreamResult result = new StreamResult(new File("C:/Users/Pratik/MapArticleURIWithNER/"+tempFileName+".rdf"));

// Output to console for testing
//StreamResult result = new StreamResult(System.out);

transformer.transform(source, result);

//System.out.println("File saved!");