【问题标题】:How can I read the Library file used in BIRT report?如何读取 BIRT 报告中使用的库文件?
【发布时间】:2017-11-01 06:04:16
【问题描述】:

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

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

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

需要帮助。

【问题讨论】:

  • 你的问题不清楚。看来您没有使用 BIRT 来运行 oder 编辑报告设计。您的问题被标记为 birt,但显然这不是关于 BIRT 使用的问题。
  • 我的问题只是关于 BIRT 报告。我需要解析和读取 BIRT 报告设计文件。Wat .rpt 设计文件中使用的库和数据集使用

标签: birt


【解决方案1】:

我以前做过类似的事情。您可以将 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;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多