Formatted output with JAXB
Hi, Please help me with the formatting of output XML file using JAXB. This is my client program that marshals xml content into xml file. This program is creating XML file with no indentation at all. I commented out the line
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
still getting same xml file with no indentation. Am I doing anything wrong?
Thanks in advance.
try {
// create a Validator
Validator v = jc.createValidator();
// validate the content tree
boolean valid = v.validate( root );
//logger.info("XML File Validated Successfully" );
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://mydomain.com/Schemas/data DT.xsd");
DataWriter writer = new DataWriter(
new OutputStreamWriter(new FileOutputStream(fileName),"UTF-8"),
"UTF-8" );
m.setProperty("com.sun.xml.bind.namespacePrefixMapper",new NamespacePrefixMapperImpl());
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(root, writer);
}catch( ValidationException ue ) {
logger.error( "Caught ValidationException"+ue ); throw new SdarsDBException("Validation Exception "+ue);
} catch( JAXBException je ) {
je.printStackTrace();
} catch( IOException ioe ) {
ioe.printStackTrace();
Hi,
try writing to the FileOutputStream directly.
I get formatted output this way.
maybe the DataWriter is doinfg some translatiopn for you?
Chris
Similar Messages
-
I'm currently taking a Java programming class using Java version 1.5.0_06 for my class.
I'm running into problems with the printf statements. Can someone help me figure out what's wrong with this statement?
outFile.printf("%-26s $ %12.2f%n", "Assessed Value:", assessVal);
Basically, I want the output to print, for example:
Assessed Value:********* $ 1000000.00 (* denotes spaces)
This is the error message I get when running it:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method printf(String, Object[]) in the type PrintWriter is not applicable for the arguments (String, String, double)
Any help is appreciated.
ntjavaWell, opened list of arguments which is used by printf method, as well as autoboxing, are 1.5 features. So when you need to compile with an old java (1.4), opened list of arguments is replaced by array of Objects. And in this case you need to write something like
printf("your format string", new Object[] {"some string", new Double(varDouble)});But in this case you need to check what java version do you use to compile it. Just execute
java -versionYou can use -source argument to specify which version of java do you use (1.4 or 1.5) in your java sources. -
Hi,
I want to display a particular word with some color. But I have to choose that word at runtime based on some condition.
for eg: there are 3 words: str1, str2 and str3.
I have to print all the words, but str2 with yellow color and others with normal color ( ie no color ).
How to do this?
Regards,
KalaiHi,
Use the FORMAT keyword
eg.
FORMAT color 3.
write str3.
FORMAT color off.
Note :
FORMAT.
Additions:
1. ... COLOR n [ON] or ... COLOR OFF
2. ... INTENSIFIED [ON] or ... INTENSIFIED OFF
3. ... INVERSE [ON] or ... INVERSE OFF
4. ... HOTSPOT [ON] or ... HOTSPOT OFF
5. ... INPUT [ON] or ... INPUT OFF
6. ... RESET
Effect
Sets or modifies the valid output format.
Notes
The formats set by FORMAT are effective from the next output operation to the list, i.e. from the next WRITE command or from the next new line.
The addition ON for switching on the relevant output format is optional.
You can also set the static additions ON, OFF and n (for COLOR) dynamically with = var (for further information, see end of this documentation).
Addition 1
... COLOR n [ON] or ...COLOR OFF
Effect
Color of line background. n can have the following values:
Reward if helpful.
regards,
LIJO JOHN. -
Have a problem in Formatting output with Escape Sequence
class Welcome
public static void main(String args[])
//Khong the hieu noi
System.out.println("Welcome\tto the world of java");
System.out.println("Happy\tBirthday");
System.out.println("Welcome\" to the world of java");
System.out.println("Bo\ttay");
System.out.println("Be\ttay");
System.out.println("Nhe\ttay");
System.out.println("Welcome\tto Viet Nam");
System.out.println("?Welcome\tto Viet Nam");
System.out.println("!Welcome\tto Viet Nam");
System.out.println("*Welcome\tto Viet Nam");
System.out.println("#Welcome\tto Viet Nam");
System.out.println("$Welcome\tto Viet Nam");
System.out.println("%Welcome\tto Viet Nam");
System.out.println("^Welcome\tto Viet Nam");
System.out.println("&Welcome\tto Viet Nam");
System.out.println("/Welcome\tto Viet Nam");
System.out.println("Welcome\tto Viet Nam");
System.out.println(" Welcome\tto Viet Nam");
System.out.println(" Welcome\tto Viet Nam");
System.out.println(" Welcome\tto Viet Nam");
System.out.println(" Welcome\tto Viet Nam");
System.out.println(" Welcome\tto Viet Nam");
System.out.println(" Welcome\tto Viet Nam");
System.out.println(" Welcome\tto Viet Nam");
System.out.println(" Welcome\tto Viet Nam");
System.out.println(" Welcome\tto Viet Nam");
System.out.println("Bodsdsadsme\ttay");
System.out.println("come\tto");
Let's explain for me...ThanksDou you have a question ?
The character and string escape sequences allow for the representation of some nongraphic characters as well as the single quote, double quote, and backslash characters in character literals and string literals:'\b' /* \u0008: backspace */
'\t' /* \u0009: horizontal tab */
'\n' /* \u000a: linefeed */
'\f' /* \u000c: form feed */
'\r' /* \u000d: carriage return */
'\"' /* \u0022: double quote */
'\'' /* \u0027: single quote */
'\\' /* \u005c: backslash */In case you are using Java 1.5, you might be interested in System.out.printf(), which usesformat string. -
Is it possible to create a Webservice in BI which takes XML as an input and gives PDF as output with an additional requirement that Siebel expecting the XSD from BI to send data in the BI requested format. Siebel wants to send the data as xml to BI but not sure of the BI capabilities on giving WSDL embedded with XSD (input is a hierarchical)
Hi All,
I am able to fulfil above requirement. Now I am stuck at below point. Need your help!
Is there any way to UPDATE the XML file attached to a Data Definition (XML Publisher > Data Definition) using a standard package or procedure call or may be an API from backend? I am creating an XML dynamically and I want to attach it to its Data Definition programmatically using SQL.
Please let me know if there is any oracle functionality to do this.
If not, please let me know the standard directories on application/database server where the XML files attached to Data Definitions are stored.
For eg, /$APPL_TOP/ar/1.0/sql or something.
Regards,
Swapnil K. -
How to download alv grid output(with field catalog) into excel file format
Hi all,
How to download alv grid output(with field catalogs) into excel file format and same file has to download to application server.
Please help.
Regards,
Satya.Hi,
On list where alv is displayed, select export icon( green color -> ),select spread sheet.
This will display records in Excel sheet. -
Formatted HTML output with Spry regions - is it possible?
I have recently begun using the XML export extension in
conjunction with an Access database to output dynamic data into a
page with a Spry master/detail setup. So far, my simple example is
going great, but I've run into a snag that I need some help with.
To explain what I'm doing - it's a simple article page with
the list of articles on the left with the title and date and the
article title and full contents on the right hand side. So far it's
all working very well, updating in real time when I click an
article title on the left. The problem is the output with this one
field which stores not only text, but also HTML formatting that is
generated by a wysiwyg editor used on the article creation side of
this little app. This HTML formatted content is the article body
and is stored in a field named the same - "body". With traditional
ASP, the HTML formatting displays as expected and all is well, but
with Spry, it doesn't output formatted HTML, but instead shows the
content and HTML code together as text. How can I get this one
field ("body") to be output so all the HTML formatting is shown?
This is my simple page example. Click through and you'll see
what I mean.
http://www.shoestodyefor.com/ajax.asp
Here's the section of code in question regarding the output
on that right hand panel where the body is displayed for each
article:
<div spry:detailregion="ds1">
{title}<br />
{entryDate}<br />
<br />
{body}
/div>
Is it possible to have that {body} section shown so the
dynamically created HTML code from the wysiwyg editor is displayed
correctly?Steve Skinner wrote:
> Is it possible to have that {body} section shown so the
dynamically created
> HTML code from the wysiwyg editor is displayed
correctly?
The version of Spry that ships with Dreamweaver CS3 (Spry
1.4) doesn't
support the type of output created by the XML Export
extension.
This issue has been corrected in Spry 1.5, but no plans have
been made
public for integrating Spry 1.5 into Dreamweaver CS3. You
would need to
download Spry 1.5 from
http://labs.adobe.com/technologies/spry/.
Details
of how to hand-code the fix for output from XML Export are
here:
http://labs.adobe.com/technologies/spry/samples/data_region/HTMLFragsInXMLSample.html
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/ -
PO output with XML and PDF format
Hi All,
I need PO output with XML and PDF format. when I give print it shld go to vendor with xml and pdf format through mail. please kindly guide me on this .
Thanks in advance
JKhi,
try this code to get in pdf form
REPORT zsuresh_test.
Variable declarations
DATA:
w_form_name TYPE tdsfname VALUE 'ZSURESH_TEST',
w_fmodule TYPE rs38l_fnam,
w_cparam TYPE ssfctrlop,
w_outoptions TYPE ssfcompop,
W_bin_filesize TYPE i, " Binary File Size
w_FILE_NAME type string,
w_File_path type string,
w_FULL_PATH type string.
Internal tables declaration
Internal table to hold the OTF data
DATA:
t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
Internal table to hold OTF data recd from the SMARTFORM
t_otf_from_fm TYPE ssfcrescl,
Internal table to hold the data from the FM CONVERT_OTF
T_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.
This function module call is used to retrieve the name of the Function
module generated when the SMARTFORM is activated
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = w_form_name
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
fm_name = w_fmodule
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Calling the SMARTFORM using the function module retrieved above
GET_OTF parameter in the CONTROL_PARAMETERS is set to get the OTF
format of the output
w_cparam-no_dialog = 'X'.
w_cparam-preview = space. " Suppressing the dialog box
" for print preview
w_cparam-getotf = 'X'.
Printer name to be used is provided in the export parameter
OUTPUT_OPTIONS
w_outoptions-tddest = 'LP01'.
CALL FUNCTION w_fmodule
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
control_parameters = w_cparam
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
output_options = w_outoptions
USER_SETTINGS = 'X'
IMPORTING
DOCUMENT_OUTPUT_INFO =
job_output_info = t_otf_from_fm
JOB_OUTPUT_OPTIONS =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
t_otf[] = t_otf_from_fm-otfdata[].
Function Module CONVERT_OTF is used to convert the OTF format to PDF
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
ARCHIVE_INDEX = ' '
COPYNUMBER = 0
ASCII_BIDI_VIS2LOG = ' '
PDF_DELETE_OTFTAB = ' '
IMPORTING
BIN_FILESIZE = W_bin_filesize
BIN_FILE =
TABLES
otf = T_OTF
lines = T_pdf_tab
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
ERR_BAD_OTF = 4
OTHERS = 5
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
To display File SAVE dialog window
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
WINDOW_TITLE =
DEFAULT_EXTENSION =
DEFAULT_FILE_NAME =
FILE_FILTER =
INITIAL_DIRECTORY =
WITH_ENCODING =
PROMPT_ON_OVERWRITE = 'X'
CHANGING
filename = w_FILE_NAME
path = w_FILE_PATH
fullpath = w_FULL_PATH
USER_ACTION =
FILE_ENCODING =
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
others = 4
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Use the FM GUI_DOWNLOAD to download the generated PDF file onto the
presentation server
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = W_bin_filesize
filename = w_FULL_PATH
FILETYPE = 'BIN'
APPEND = ' '
WRITE_FIELD_SEPARATOR = ' '
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
IMPORTING
FILELENGTH =
tables
data_tab = T_pdf_tab
FIELDNAMES =
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
reward points if useful,
siri -
Can we Compare PDF Output with CSV format
Team,
Can we Compare PDF Output with CSV format.
In Excel I need to two text boxes asking us to browse the files and compare the files PDF & CSV format.
Please suggest me if we have solution for this.
Thanks!
KiranHi
I'm afraid the Excel Application does not support this function currently, I am suggesting you to take advantage of a third party component to achieve this goal.
Thanks for your understanding.
Best Regards
Lan
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Excel output (with graphics)
Hello,
I am using Oracle reports 10g 1.2.0 version.
We need to generate oracle reports in Excel format ("real" Excel, not delimited text) with tabular data and
also graphics.
I used desformat=spreasheet. But is is giving only one worksheet.
I've found the "Output to Excel with Oracle9i Reports"
demo but the Excel template in the demo is very simple and doesn't have graphics.
Then I've found the following:
http://otn.oracle.com/products/reports/htdocs/getstart/examples/excel_output/result/excel.jpg
a) The above site has excel output with multiple worksheets.
which is similar to what we need but I wasn't able to find related source (excel_emp.jsp).
b) Using jsp if we can ahieve multiple worksheets with grapahics, please provide us examples.
c) http://www.oracle.com/technology/products/reports/htdocs/getstart/demonstrations/excel/index.html --This site is not working to find the demo.
Could you please help me in this?
Thank you for any help.carla,
the example you mentioned uses the JSP web source that is only available in oracle9i reports.
in theory you can create any excel output. it is just a matter of creating the template and then adding the reports tags to populate it with data.
you could then use reports' URL engine to produce files from this output.
there are certainly ways to do it, but they are only available in oracle9i reports (9.0.2 and higher)
regards,
philipp -
Initial-page-number not working in RTF format output
A report has a parameter for the page number to start with. In rtf template below code is present
<?initial-page-number:xdoxslt:ifelse(P_FIRST_PAGE_NUM!=’’,number(P_FIRST_PAGE_NUM),1)?>
The report page number starts with the value which we pass in p_first_page_num in PDF format but in rtf format output it always starts with 1.
Is initial-page-number not supported in RTF format output ? If not then what is the alternative?the method u followed is fine as need a page number staring from a specify value which u input.
@section is only for resetting page number to 1 for every group and for that pdf and ppt will be fine but only for rtf u need to use that ( pressing F9).
u can use @section and initial page number combined but they give u same output as get now. rtf output wont support it will only reset 1 every time
What ever u do rtf output wont support initial page number code ..........
i mentioned that F9 work around to mention that it is the only work around u have upto now to control rtf output with regards to page number.
Guru's correct me if i am wrong. wait for a day or two if some one from guru's confirm it .
If u need real confirmation raise an SR oracle will let u know . -
With Java 1.4.2:
What is the correct way to format output in the java.io.PrintStream?
The following is incorrect, even though it is still used in the The JavaTM Tutorial at: http://java.sun.com/docs/books/tutorial/essential/
System.out.formatThis returns "cannot resolve the method 'format'"
Any detailed suggestions or information is greatly appreciated.The following is incorrect, even though it is still
used in the The JavaTM Tutorial at:
http://java.sun.com/docs/books/tutorial/essential/
The whole format thing has been introduced in 1.5. The tutorial also states it's been "updated to 1.5.".
That's all I've got to say for I don't know how you can format a PrintWriter, let alone a PrintStream, prior to 1.5. I'm not really sure there is any way. Any "legacy way", that is. There almost certainly are third-party API which achieve similar results. -
Writing binary data in same format as with FORTRAN code
Hello,
I would like to write out data in a binary format that is used by FORTRAN unformatted direct access files. I have some code in FORTAN that produces the correct format; however, I have been unable to reproduce the output with a Java method.
The FORTAN code to write an array Z is:
REAL Z(72,46,16)
OPEN(8,FILE='grads.dat',FORM='UNFORMATTED',
& ACCESS='DIRECT',RECL=72*46)
IREC=1
DO 10 I=1,16
WRITE (8,REC=IREC) ((Z(J,K,I),J=1,72),K=1,46)
IREC=IREC+1
10 CONTINUE
The Java code I was able to come up with to write out an array arrTS produces binary data differently:
FileOutputStream fosOut = new FileOutputStream(filename,false);
for(int x=0; x<this.xmax; x++) {
for(int y=0; y<this.ymax; y++) {
ByteArrayOutputStream bosOut = new ByteArrayOutputStream(2);
DataOutputStream dos = new DataOutputStream(bosOut);
dos.writeFloat((float)this.arrTS[x][y]);
byte[] arrByte = bosOut.toByteArray();
fosOut.write(arrByte);
fosOut.close();
Any help is greatly appreciated.
Best regards,
StefanI am using a software to read in the data that I am calculating in Java. I cannot easily change the format that software is reading; therefore, ASCII is not an option.
The software that reads the data states something about "Little-endian". Do you which Java classes to use for that?
Best regards,
Stefan
First, you need to find out the format of yourFORTRAN
output. Is it ASCII? EBCDIC? BCD? IEEE?
Big-endian? Little-endian?
Until you know that you won't know which Javaclasses
to use.Also I wouldn't be too sure different FORTRAN
compilers use the same data format.
In my view the best system interchange format still is
the ASCII text file. Why don't you let the Fortran
program use it to write its data to file. It should be
no problem reading it from Java. -
Marshalling HashMap with JAXB 2.0 - empty tags & ill schema
Hi all,
I expected JAXB 2.0 to be capable to handle basic classes like HashMap, but it does not look so. I have two classes: SimpleNegotiationManager which has a property HashMap in which are stored the instances of SimpleInitiatedConversation:
package xml;
import javax.xml.bind.annotation.*;
import java.util.HashMap;
@XmlAccessorType(AccessType.FIELD)
@XmlRootElement
public class SimpleNegotiationManager {
@XmlElement
protected HashMap<String, SimpleInitiatedConversation> initiatedConversations;
public SimpleNegotiationManager() {
public HashMap<String, SimpleInitiatedConversation> getInitiatedConversations() {
if (initiatedConversations == null) {
initiatedConversations = new HashMap();
return initiatedConversations;
public void setInitiatedConversations(HashMap<String, SimpleInitiatedConversation> initiatedConversations) {
this.initiatedConversations = initiatedConversations;
}and
package xml;
import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@XmlAccessorType(AccessType.FIELD)
@XmlType
public class SimpleInitiatedConversation {
@XmlElement
protected List<String> messages;
protected String conversationID;
protected int protocolState;
public SimpleInitiatedConversation() {
public List<String> getMessages() {
if (messages == null) {
messages = new ArrayList();
return messages;
public void setMessages(List<String> messages) {
this.messages = messages;
public int getProtocolState() {
return protocolState;
public void setProtocolState(int protocolState) {
this.protocolState = protocolState;
public String getConversationID() {
return conversationID;
public void setConversationID(String conversationID) {
this.conversationID = conversationID;
}When I marshalled SimpleNegotiationManager while the HashMap was filled with several <String,SimpleInitiatedConversation> entries, in the output were empty tags initiatedConversations:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<simpleNegotiationManager>
<initiatedConversations>
</initiatedConversations>
</simpleNegotiationManager>When I used schemagen to generate a schema, it produced:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="simpleInitiatedConversation">
<xs:sequence>
<xs:element name="messages" type="xs:string" maxOccurs="unbounded" minOccurs="0"/>
<xs:element name="conversationID" type="xs:string" minOccurs="0"/>
<xs:element name="protocolState" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:element name="simpleNegotiationManager" type="simpleNegotiationManager"/>
<xs:complexType name="simpleNegotiationManager">
<xs:sequence>
<xs:element name="initiatedConversations" type="hashMap" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="hashMap">
<xs:complexContent>
<xs:extension base="abstractMap">
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="abstractMap" abstract="true"/>
</xs:schema>Particularly the description of HashMap seems ill - there is not specified that the HashMap has keys String and values SimpleInitiatedConversation.
Unfortunatelly, the j2s-xmlAdapter-field example available with JAXB 2.0 is more complicated than I need. I just need to store/load HashMap into/from XML and I do not care what it looks like. Is it possible to avoid extending XmlJavaTypeAdaptor for a simple storing a HashMap into XML? Perhaps I use improper annotations in the source code, but I cannot get it working. Any clue?Ok i figured out one way of doing this by using some classes from JAXP...
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema s = null;
try{
s = sf.newSchema(new File("Sources/schema/test.xsd"));
}catch(Exception e){
System.err.println("Exception e: " + e.getMessage());
marshaller.setSchema(s);
//MyValidationHandler class implements the ValidationEventHandler interface
MyValidationHandler gv = new MyValidationHandler();
marshaller.setEventHandler(gv);If anyone has something to add let me know!! -
XML (un)marshalling with JAXB and "any" blocks
I have 2 very simple XSD schema's.
SchemaA.xsd:
[request]-------[element_A] is xs:string
|__(ANY)
SchemaB.xsd:
[body]--------[element_B] is xs:string
The any block says that there can follow any type of xml after the element_a.
In the xsd it is coded as: <xs:any />
I compiled both schema's with jaxb, using this command line:
xjc SchemaA.xsd -p test.request
xjc SchemaB.xsd -p test.body -use-runtime test.request.impl.runtime
I created the following code :
test.request.ObjectFactory of1 = new test.request.ObjectFactory();
test.body.ObjectFactory of2 = new test.body.ObjectFactory();
Request r = of1.createRequest();
r.setElementA("testing, element one");
Body b = of2.createBody();
b.setElementB("testing, element two");
r.setAny(b);
Marshaller m = of1.createMarshaller();
m.marshal(r,System.out);
And the result is what I expected:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<request><element_a>testing, element one</element_a><body><element_b>testing, element two</element_b></body></request>
JAXB added the xml from the second schema to the first.
Ok, so far so good. Now I'm trying to do it the other way around, I want to unmarshall that XML to objects again:
String xml <- contains the outputted xml from the marshall (as pasted a few lines above)
Unmarshaller um = of1.createUnmarshaller();
Request r2 = (Request)um.unmarshal(new ByteArrayInputStream(xml.getBytes()));
System.err.println(r2.getElementA());
System.err.println(r2.getAny());
The output:
testing, element one
null
now, the first message is good. The second is not however...why is the "getAny" null ? I can't figure this one out. In the best possible case it should return an object that can be cast to "Body" .
In the worst case it should just return the "<Body> ...." xml as string. But not null ...
Any help on this is appreciated !JAXB does not support xs:any
Maybe you are looking for
-
IPhone 5s will not sync to facebook calendar
Hi Everyone, I am new to both the iPhone 5s and Apple. I have just installed facebook onto my iPhone and for some unknown reason the Facebook Events and Birthdays will not sync with the iPhone calendar. Can anyone advise me on how can I can get this
-
Charging adapter only charges plugged in one direction
I have an issue I didn't have before Apple changed out the logic board. Now when I plug in a power apter it will only.charge or work plug in in one direction. It is a hassle with a right angle adapter as when it is plugged in and working can't use th
-
Minimum subset of a set, whose union is same as original set?
hi, if you have a Set of Sets called S, e.g. {{1,2},{2,3},{3,4}} and want to find the/a minimum subset of S called S', which has the property that union(S)==union(S') eg union({{1,2},{2,3},{3,4}})==union({{1,2},{3,4}}) where union(S) means the union
-
EXIF tag used as 'Description'
What EXIF tag does iPhoto 09 use as description when I import JPGs? With iPhoto 08 it worked when I set the 'Object Name' before importing but since I upgraded to 09 that does no longer work I can still see the description for photos I imported when
-
Advanced Window Open 3 Extension Problem
I am fairly new to Dreamweaver 8 and just purchased Advanced Open Window 3. I am trying to open a new browser with an html paged centered in full screen mode. The new browser opens full screen but the page is always center TOP. The Open Window positi