如何读取 BIRT 报告中使用的库文件?

How can I read the Library file used in BIRT report?

任何人都可以指导/帮助我..如何阅读 BIRT 报告并获取报告中使用的库和数据集。

我尝试使用所有不同的解析器来读取文件。每次我得到 org.apache.xerces.jaxp.SAXParserFactoryImpl 无法转换为 javax.xml.parsers.SAXParserFactory --ERROR.

后来我尝试了 Apache Xerces - DOM Parser 当我使用 Apache Xerces - DOM 解析器时,我可以解析 XMl format.But 中的报告,我无法阅读它...抛出错误。

需要帮助。

我以前做过这样的事情。您可以使用 jdk 中嵌入的标准解析器以及 XPath

  1. javax.xml.parsers.*
  2. javax.xml.xpath.*
  3. 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;
    }