任何人都可以指导/帮助我..如何阅读BIRT报告并获取报告中使用的图书馆和数据集。
我尝试使用所有不同的Parsers来读取文件。每次我都会这样做 org.apache.xerces.jaxp.SAXParserFactoryImpl无法强制转换为javax.xml.parsers.SAXParserFactory --ERROR。
后来我尝试了Apache Xerces - DOM Parser 当我使用Apache Xerces - DOM Parser时,我可以解析XMl格式的报告。但我无法读取它...投掷错误。
需要帮助。
答案 0 :(得分:0)
之前我做过类似的事。您可以在jdk中使用标准解析器以及XPath
javax.xml.parsers.*
javax.xml.xpath.*
org.w3c.dom.*
下面是一个示例代码,如果您仔细阅读,我想您会明白这一点。
//this path contains dataset start
public static final String RPTLIBRARY_XPATH_DATA_SET_NODE_START = "//library/data-sets/oda-data-set[@name='";
//this path contains SQL in rptlib
public static final String RPTLIBRARY_XPATH_QUERYTEXT_NODE_END = "']/xml-property[@name='queryText']";
public Document getXMLAsDocumentObject(InputStream is) throws ParserConfigurationException, SAXException, IOException{
DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = dBuilder.parse(is);
doc.normalize();
return doc;
}
public Node getNode(Element element, String xPath) throws XPathExpressionException{
_log.debug(xPath);
XPathExpression xPathExpression = XPathFactory.newInstance().newXPath().compile(xPath);
Node tableNode = (Node) xPathExpression.evaluate(element, XPathConstants.NODE);
return tableNode;
}
public NodeList getNodeList(Element element, String xPath) throws XPathExpressionException{
_log.debug(xPath);
XPathExpression xPathExpression = XPathFactory.newInstance().newXPath().compile(xPath);
NodeList nodeList = (NodeList) xPathExpression.evaluate(element, XPathConstants.NODESET);
return nodeList;
}