Jump to content
We've recently updated our Privacy Statement, available here ×

Cannont resolve namespace prefix \'rdf\' - XML data source


clandestino

Recommended Posts

I need to set xml document as data source for jrxml file.

I can see that it works with simple xml (without namespace prefix). But whole my xml documents are with namespace prefixies.

 

My document:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dct="http://purl.org/dc/terms/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rim="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0" xmlns:ows="http://www.opengis.net/ows" xmlns:dcmiBox="http://dublincore.org/documents/2000/07/11/dcmi-box/">
    <rdf:Description about="http://dublincore.org/">
        <dc:title xml:lang="en">USA Topographic Map </dc:title>
        <dc:description>This service presents land cover imagery for the world and detailed topographic maps for the United States. The service includes NPS Natural Earth physical map at 1.24km per pixel for the world at small scales, i-cubed eTOPO 1:250,000-scale maps for the contiguous United States at medium scales, and National Geographic TOPO! 1:100,000 and 1:24,000-scale maps (1:250,000 and 1:63,000 in Alaska) for the United States at large scales. The TOPO! maps are seamless, scanned images of USGS paper topographic maps.</dc:description>
        <dc:identifier>http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer</dc:identifier>
        <dc:type>MapServer</dc:type>
        <dc:creator>ESRI</dc:creator>
        <dct:references>http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer</dct:references>
        <ows:WGS84BoundingBox>
            <ows:LowerCorner>-179.999999 -89.999999</ows:LowerCorner>
            <ows:UpperCorner>179.999999 89.999999</ows:UpperCorner>
        </ows:WGS84BoundingBox>
    </rdf:Description>
</rdf:RDF>

 

And with my jrxml document I just want to print simple data suche as <dc:type> tag:

 

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="rdf" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString language="xPath">
        <![CDATA[/rdf:RDF]]>
    </queryString>
    <field name="dc:type" class="java.lang.String">
        <fieldDescription><![CDATA[/rdf:RDF/rdf:Description/dc:type]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <staticText>
                <reportElement x="35" y="0" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[/rdf:RDF/rdf:Description/dc:type]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField>
                <reportElement x="35" y="19" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{dc:type}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

 

I am using the following code for filling the document:

Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream("data/documentRDF.xml"));
        params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
        params.put(JRXPathQueryExecuterFactory.XML_DATE_PATTERN, "yyyy-MM-dd");
        params.put(JRXPathQueryExecuterFactory.XML_NUMBER_PATTERN, "#,##0.##");
        params.put(JRXPathQueryExecuterFactory.XML_LOCALE, Locale.ENGLISH);
        params.put(JRParameter.REPORT_LOCALE, Locale.US);
       
       
        JasperFillManager.fillReportToFile("build/reports/rdf.jasper", params);

 

and my jasperreports.properties is:

net.sf.jasperreports.xpath.executer.factory=net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory
net.sf.jasperreports.query.executer.factory.XPath=net.sf.jasperreports.engine.query.JaxenXPathQueryExecuterFactory
net.sf.jasperreports.xml.detect.namespaces=true

Pleas tell me what am I doing wrong.

 

My error log:

net.sf.jasperreports.engine.JRException: XPath selection failed. Expression: /rdf:RDF
    at net.sf.jasperreports.engine.util.xml.JaxenXPathExecuter.selectNodeList(JaxenXPathExecuter.java:93)
    at net.sf.jasperreports.engine.data.JRXmlDataSource.moveFirst(JRXmlDataSource.java:263)
    at net.sf.jasperreports.engine.data.JRXmlDataSource.<init>(JRXmlDataSource.java:174)
    at net.sf.jasperreports.engine.query.JRXPathQueryExecuter.createDatasource(JRXPathQueryExecuter.java:90)
    at net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:684)
    at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:605)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1281)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:901)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:118)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:435)
    at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:220)
    at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:126)
    at XmlDataSourceApp1.fill(XmlDataSourceApp1.java:235)
    at TestJasper.test(TestJasper.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.jaxen.UnresolvableException: Cannot resolve namespace prefix 'rdf'
    at org.jaxen.expr.DefaultNameStep.matches(DefaultNameStep.java:358)
    at org.jaxen.expr.DefaultNameStep.evaluate(DefaultNameStep.java:209)
    at org.jaxen.expr.DefaultLocationPath.evaluate(DefaultLocationPath.java:140)
    at org.jaxen.expr.DefaultAbsoluteLocationPath.evaluate(DefaultAbsoluteLocationPath.java:113)

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

I fould your instruction from the above link, but it didn't work for me. It returns the same error.

 

Can you explain a little bit procedure. The xml I wan't to parse is:

 

<rdf:RDF>

<rdf:Description>
<dc:identifier>{15C78BBF-133F-4261-843F-EE993C83A6EE}</dc:identifier>
<dc:title>SimpleRDF</dc:title>
<dc:language>eng</dc:language>

<ows:WGS84BoundingBox>
<ows:LowerCorner>-20.5179</ows:LowerCorner>
<ows:UpperCorner>43.0585 66.618</ows:UpperCorner>
</ows:WGS84BoundingBox>
</rdf:Description>
</rdf:RDF>

 



Post Edited by clandestino at 03/08/2011 10:17
Link to comment
Share on other sites

1. Don't use JRXmlUtils.parse(...). As I explained here ( http://jasperforge.org/plugins/mantis/view.php?id=4500), 

it uses a DocumentBuilderFactory that is not namespace aware by default. Instead you shoud use something like this:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

dbf.setValidating(false);

dbf.setIgnoringComments(true);

dbf.setNamespaceAware(true);

DocumentBuilder builder = dbf.newDocumentBuilder();

Document document = builder.parse(JRLoader.getLocationInputStream("data/documentRDF.xml"));

params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);

...

The bolded line is what matters in this case.

2. Pay attention when you set the query executer factories. In your properties file you have:

net.sf.jasperreports.query.executer.factory.XPath = ...

and in your report you use:

<queryString language="xPath">...

Notice the case of the 'X' in both situations? It must be the same, otherwise the factory is the default one configured with the lower case 'X' in default.jasperreports.properties:

net.sf.jasperreports.query.executer.factory.xPath = ...

 

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...