我有一个将在Java应用程序中处理的XML文档。 但是,我需要使用XSLT文件对其进行转换,以便以后可以进行处理。在处理之前用XSLT转换XML文档
这就是我现在如何加载XML文件。
DocumentBuilderFactory factory;
DocumentBuilder docbuilder;
Document doc;
Element root;
factory = DocumentBuilderFactory.newInstance();
try
{
// open up the xml document
docbuilder = factory.newDocumentBuilder();
doc = docbuilder.parse(new FileInputStream(m_strFileName));
// get the document type
doctype = doc.getDoctype();
strDTD = doctype.getPublicId();
// get the root of the document
root = doc.getDocumentElement();
// get the list of child nodes
nodes = root.getChildNodes();
// now process each node
...
}
catch(ParserConfigurationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch(SAXException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
如何将XSLT转换应用于XML文档,然后获取新文档的根节点?
请注意,我是而不是想要将生成的xml树写入磁盘。
谢谢,这很有帮助。我是否理解正确,产生的文档现在存储在'doc'中? (多么奇怪的API ......) – dokaspar
@dokaspar - 是的,你说得很对,最终的文档确实保存在变量“doc”中。 – Simon