Scenario:
I am trying to unmarshall the Acord XML(Insurance standard XML) to Java-Acordform and then trying to map the Acordform object to a one more formbean-Policformbean in order to display the values in the JSP where user can edit the values.Again I have to marshall the Java object values to XML.There is an XSD available for this Acpord XML.Suing XMLSpy I have created XSD from XML.Using XJC I have created the java objects from XSD.
Since Acord being a complex XML and the structure of the generated Java object is not straight forward I have created Policformbean.Using Policformbean , I am tring to display the values in the JSP.
Issue:
I am facing few issues while setting the acordform to Policformbean.May I know if using JAXB is the best approach for me to display the XML element values when Acord XML is used?
If anyone has worked on JAXB conversion from Acord XML to Java object values, please guide me.
Thanks in Advance.
Related
I am using postgresql as database. In db i have one column which contains xml with language codes. I want to parse that xml and get value trough the report language.
select o.name,o.price from bookdefinations o This o.name contains that xml value:
<?xml version="1.0" encoding="UTF-8"?>
<values>
<en-us>en value</en-us>
<es>es value</es>
<ru>ru value</ru>
<tr>tr value</tr>
</values>
Can i parse this with jasper's expressions or can i parse while selecting from db (i dont have any idea how to get report language in select query and parse xml in select)
There is a xmldatasource for jasperreport, you can do a subreport and send the blob to that subreport as an xmldatasource, then you can parse the xml in the subreport and show the content, I'm not sure if you want to show the values or the entire xml, if it is a report I guess you should show the values in a pretty way I mean not as xml, check this link
http://jasperreports.sourceforge.net/sample.reference/xmldatasource/
You could do this directly in postgresql during the select.
PostgreSql has an XML Type and various XML functions.
If you take a look at those functions, you'll see the xpath function which can be used to extract data from XML types during a select statement.
For a reference to xPath, take a look at the tutorial from W3Schools.
I want to parse XML file using SaxParser. I'm trying to fetch the data associated to a tag or its attributes. The XML is in the following format.
<con>
<fig>
<abc>
<name xyz="">
<id>2</id>
</name>
</abc>
</fig>
</con>
I tried with couple of example but not succeeded in the fetching the data, I am requesting you to provide me any suggestion or and working example to increase my knowledge on parsing using SAX.
Use a DOM parser as your xml is very small and its easy to get what you are asking for.
There are my example and help available online, Please Google your question before posting on the stack over flow from next time.
Please check the following links which has good example for saxParsing
How to read XML file in Java – (SAX Parser)
Getting Attributes And its Value
hope this help you.
i have been used JDOM to perform xml data entry & updation in any XML file, but now i am trying to use JAXB instead of JDOM but getting some difficulties.
as i know marshalling & unmarshalling in jaxb but when it comes to entry a new data into a xml at specified location (node), i find difficulties. e.g. for new entry Japan where id = Asia
<file>
<parent>
<node id="Asia">
<name>India</name>
<name>China</name>
</node>
<node id="Europe">
<name>UK</name>
</node>
</parent>
</file>
is there anybody who has idea about it.
If I'm not mistaken JAXB and JDOM and completely different things. JAXB will serialize java objects into an XML format and vice versa. JDOM simply reads in the XML file and stores it in a DOM tree which can then be used to modify the xml itself.
Using JAXB in this way is like trying to at runtime add a new variable to a class. It cannot be done. (at least to my knowledge).
I am trying to implement this use case in a RESTful manner in my Spring MVC application. Imagine having a POJO called SalesReport with a list of Sales. Using content negotiation I'm able to return the XML and JSON representations. For example...
<SalesReport>
<Sale>...</Sale>
</SalesReport>
For my HTML representation it needs to be sexier, of course. The requirement is to display a chart using Highcharts as well as the data in table format. Pretty standard stuff. I am unsure of how to accomplish this in an elegant way. I thought about
Serializing SalesReport to an XML/JSON formatted String and doing request.setAttribute(). I feel like this couples my controller with my view. My XML and JSON representations don't need this.
Making an AJAX call to get the data after the JSP loads. This seems wasteful to make another HTTP request and my data is not cached either.
Create util class with functions that uses Spring MVC's JSON and XML libs to return the serialized format I need. Then in the JSP do something like <%= RestUtil.toJSON(salesReport) %>. This way my controller doesn't know specifics about my HTML view and I'm not sending extra HTTP calls.
What is a good approach to this?
Why would you use JSON/XML in the JSP? Using content-negotiation text/html should correspond with a controller method. You can access the POJO directly with the spring-form tld or JSTL in the jsp.
Assuming you have the view resolver set up:
#RequestMapping("salesreport")
public String getSalesReport(ModelMap model) {
model.addAttribute("reports", salesReportService.findAll());
return "reports/view";
}
In reports/view.jsp:
<c:forEach items="reports" var="report">
Field 1: ${report.field1} <br/>
Field 2: ${report.field2}
</c:forEach>
I am dynamically creating a DOM object and need to add following doctype to the XML file in java:
<!DOCTYPE MyXml [<!ATTLIST node id ID #REQUIRED>]>
I am using org.w3c.dom, is there any way we can do this?
Regards,
Abhishek
The org.w3c.dom just provides the interfaces for the DOM. Are you implementing these interfaces?
Otherwise, if you are using a library like JDOM, it's very simple.
See http://www.jdom.org/docs/apidocs/org/jdom/DocType.html