ikaaki Posted June 12, 2008 Share Posted June 12, 2008 Hello, I'm using an XML file for creating a report.The XML file has a structure like this:Code:<?xml version="1.0" encoding="UTF-8"?><report id="321" label="111111"> <tab id="label1" label="label1"> <refs id="refs1" label="refs1"> <ref id="ref1" label="ref1">xxxxx</ref> <ref id="ref2" label="ref2">UUU</ref> </refs> </tab> <tab id="tab2" label="tab2"> <refs id="tab2 refs1" label="222"> <ref id="project" label="Project" type="combobox">A</ref> </refs> </tab></report> When I try to read through the first ref in second refs in the first tab and display this value in a text field.I used this code: Code:[code]tab[1]/refs[2]/ref[1]This works. But, the numbers of elements "tab","refs","ref" are not stable.Code:[code]tab[10]/refs[20]/ref[50] maybe exist.The values of id and label are not static too.So Code:[code]/tab/refs/ref[@id="xxx"] doesn't work neither.I also tried to use variable, but it doesn't work.Please Anyone knows how to solve this problem?Thanks very much. Best regards,Wei Link to comment Share on other sites More sharing options...
ikaaki Posted June 13, 2008 Author Share Posted June 13, 2008 Anyone, please. Link to comment Share on other sites More sharing options...
lshannon Posted June 13, 2008 Share Posted June 13, 2008 I am not very good with XPath so I am not sure if I can help much with this. I can suggest an alternate approach. Perhaps you can create a query executer that takes in the XML and returns a JavaBean collection?http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/data/JRBeanCollectionDataSource.html You could use an API like this to convert the XML to JavaBeans:http://xmlbeans.apache.org/ Once you get the data in a bean collection, processing it in the report might be easier than messing with XPath. Just a thought. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now