How to change xml declaration using jaxb Marshaller

please, my xml declaration, in the output file generated by jaxb: javax.xml.bind.Marshaller is:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
I need to change it in:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
I don't have idea about how to change.
thanks a lot alessandro

Hello.
public void saveJaxbObjectToFile(String packageName, Object myJaxbObject, String fileName)
throws JAXBException, ParserConfigurationException, TransformerConfigurationException,
TransformerException, FileNotFoundException, IOException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
org.w3c.dom.Document document = db.newDocument();
JAXBContext jAXBContext = JAXBContext.newInstance(packageName);
Marshaller m = jAXBContext.createMarshaller();
m.marshal(myJaxbObject, document);
ProcessingInstruction processingInstruction = document.createProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"style.xsl\"");
Node rootElement = document.getDocumentElement();
document.insertBefore(processingInstruction, rootElement);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer = transformerFactory.newTransformer();
transformer.setOutputProperty("indent", "yes");
transformer.setOutputProperty("encoding", "UTF-8");
transformer.setOutputProperty("version", "1.0");
FileOutputStream fos = new FileOutputStream(fileName);
transformer.transform(new DOMSource(document), new StreamResult(fos));
fos.flush();
fos.close();
Good luck.

Similar Messages

  • How to read the attribute of the xml file using jaxb

    Thanks,
    Buddy as i have a issue i have to read the xml file using jaxb and xml file contains this data and i have read the attribute like name , desc and action for a particular menu name pls tell the code how to do this it will be a great favour to me
    thanx in advance
    Rasool
    <contextmenu>
    <menu name='Lead' >
    <menuitem name='newlead' desc='New Lead' action='/leads.do?dispatch=insert' />
    <menuitem name='editlead' desc='Edit Lead' action='' />
    <menuitem name='leadinfo' desc='Lead Information' action='' />
    </menu>
    <menu name='Cases' >
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    </menu>
    <menu name='Contact' >
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    </menu>
    </contextmenu>

    What my program do is to get the encoding of XML files and convert them to UTF-8 encoding files, while I need this "encoding" information of the original XML document thus I can convert...
    After reading specifications and JDOM docs, the truth turns to be disappointed, no function is provided to get this information in JDOM level 2(the current released one), while it's promissed that this function will be provided in JDOM level API....
    Thanx all for your help and attention!!!

  • Change XML declaration from single quote to double quote

    Hi all,
    i have the following problem in my File Receiver Adapter. My XML File has the declaration <?xml version='1.0' encoding='utf-8'?> (With single quotes ') and want to change it to <?xml version="1.0" encoding="utf-8" ?> (With double quotes ")
    I use the XMLAnonymizerBean but this does not change the XML declaration.
    Any ideas how to change the declaration
    Thanks Max

    Hi Suraj,
    on the Modul Tab i have the following:
    1 | AF_Modules/XMLAnonymizerBean | Local Enterprise Bean | Anonymizer
    2 | CallSapAdapter                                | Local Enterprise Bean | 0
    Anonymizer | anonymizer.acceptNamespaces | http://Post.AG/PartnerInterface/Schemas/PVSdeAt/Aviso_V1.0 ns0 http://PostAG.PartnerInterface.Schemas.PVS_deAt.AvisoHeader ns1 http://PostAG.PartnerInterface.Schemas.PVS_deAt.AvisoShipper ns2
    Anonymizer | anonymizer.quote                        | "
    That is all what i have on the module tab.
    I send the data as Text (not Binär). Thats all what i have in the adapter. Do you need any further information?
    Regards, Max

  • How to access xml file using c

    how to access xml file using c. are there any libraries regarding xml fastinfoset in c? Please let me know about any resources if u know? thanks!!!
    samitha

    There are different methods to access XML data which have pro's and cons. Let us know more about what you want to do and we can help you.

  • How to change outlook mail using Word to try and open PDF to Adobe Reader XI?

    how to change outlook mail using Word to try and open PDF to Adobe Reader XI?

    I've never found technology to make life easier. It mainly offers the promise (often unfulfilled) of making it cheaper or quicker. This didn't happen when the Girl Guides put a form in an envelope and posted it. But they probably laid off the person whose job that was with the promise of everything being easy on the internet.
    PDF has, curiously, become a victim of its own success. A few years ago, you could say to people "You need Adobe Reader" and it was the only serious game in town. So they got it and it works. Now everyone is making their own PDF reader for whatever reason, fewer and fewer people can be sure of having Reader. (PDF readers come at least with every Mac, every Windows 8 system, Chrome and FireFox, which covers a LOT of ground).
    This is coupled with a bizarre decision Adobe made a few years ago to have two kinds of form, one of which all the other software fails with (and, as I noted, even Adobe's own software on iPad and Android fails). This was a neat idea which was designed for big corporations. Then the really big mistake: giving everyone with Acrobat the tools to make these new kinds of form, and making it seem they were preferre or the only game in town. This is finished now (Acrobat 11 doesn't include this big boy's software) but the damage is done, oh how it is done.
    Even regular forms tend to only work properly in real Adobe Reader. The fact is, if you make or distribute PDF forms you need to tell people to use Adobe Reader, and to know exactly how to help them do that. If people can't do that or their users won't be motivated to bother, then PDF forms are no longer a suitable choice. Sad but true.

  • How to change the browser used for Google search from context menu of selected text?

    How to change the browser used for Google search from context menu of selected text?
    It uses Safari. But I want to use Chrome (it's my default browser).

    How to change the browser used for Google search from context menu of selected text?
    It uses Safari. But I want to use Chrome (it's my default browser).

  • I need help I can't remember my iTunes Security Questions and have no idea how to change them just used a $20 gift card

    I need help I can't remember my iTunes Security Questions and have no idea how to change them just used a $20 gift card

    If you have a rescue email address (which is not the same thing as an alternate email address) on your account then you can use that to reset them : http://support.apple.com/kb/HT6170
    If you don't have a rescue email address (you won't be able to add one until you can answer your questions) then you will have to contact Support in your country to get the questions reset.
    Contacting Apple about account security : http://support.apple.com/kb/HT5699
    If your country isn't on that page then try this form and explain and see what they reply with : https://ssl.apple.com/emea/support/itunes/contact.html
    When they've been reset (and if you don't already have a rescue email address) you can then use the steps on this page to add a rescue email address for potential future use : http://support.apple.com/kb/HT5620
    Or, if it's available in your country, you could change to 2-step verification : http://support.apple.com/kb/HT5570

  • How ejb-jar.xml is Used by ejb Container

    Hi,
        Can anyone please explain me about how ejb-jar.xml is Used by ejb Container when a request is sent by a client(ie StandAlone program or a WebService)
    Thanks in Advance
    Venkat.

    Hi Benny,
    Nice answer to a self explainig question :-).
    Regards,
    Daniel
    p.s. THX to Sun and J2EE 5 and especially EJB3 (and don't forget about SAP, NWCE is really cool!!!)

  • How to add XML declaration to document using JDOM?

    Hi, there:
    I am trying to create a document. I want to add the following xml declaration to
    the document:
    <?xml version="1.0"?>
    JDOM Document class can add elements and attributes or doctype, does it have ability to add xml declaration to the very start of a document?
    regards,

    that line should be added automatically to the document when you serilize your DOM.

  • How to make XML element used in RTF PRIVATE/PUBLIC ? I know how to hide columns in RTF, but dont know how to generate the xml in below way. Please help.

    Hi
    I am following below link to hide/show my columns dynamically. See "Column Formatting"
    http://docs.oracle.com/cd/E12844_01/doc/bip.1013/e12187.pdf
    As per doc, element can be made private/public.
    <items type="PUBLIC">
    <item>
      <name>Plasma TV</name>
      <quantity>10</quantity>
      <price>4000</price>
    </item>
    <item>
    And same can be used to hide the column using condition
    <?if@column:/items/@type="PUBLIC"?>
    MY QUESTION IS HOW TO DO THIS IN MY XML BELOW?
    Below is part of my XML code which I am using in Data Definition for RTF.
    <group name="GH3" source="QH3">
    <element name="COLUMN_HEAD3" value="COLUMN_NAME" />
    </group>
    <group name="GH4" source="QH4">
    <element name="COLUMN_HEAD4" value="COLUMN_NAME" />
    </group>
    I am getting output like this.
    <LIST_GH3>
    <GH3>
    <COLUMN_HEAD3>REBILL_TO_OTHER_BUSINESS_UNIT</COLUMN_HEAD3>
    </GH3>
    </LIST_GH3>
    <LIST_GH4>
    <GH4>
    <COLUMN_HEAD4>XYZ</COLUMN_HEAD4>
    </GH4>
    </LIST_GH4>
    In order to use logic as per oracle document I want output like this.
    <LIST_GH3 type="PUBLIC">
    <GH3>
    <COLUMN_HEAD3>REBILL_TO_OTHER_BUSINESS_UNIT</COLUMN_HEAD3>
    </GH3>
    </LIST_GH3>
    <LIST_GH4 type="PRIVATE">
    <GH4>
    <COLUMN_HEAD4>BLANK</COLUMN_HEAD4>
    </GH4>
    </LIST_GH4>
    What changes I need to make in my XML code to get the runtime output as above? Please help. Where do i need to make changes in the above xml? Group name? Element name?
    I am planning to use below condition in RTF template to hide the column,  but dont know how to set the type of column as PRIVATE/PUBLIC in the XML output used to populate data in the RTF at runtime.
    <?if@column:/BTSPIEXP/LIST_GH3/@type=”PUBLIC”?>COLUMN_HEAD3<?end if?>
    Regards,
    Swapnil K.

    Hi,
    Issue has been resolved. I used the value of the element to determine to display it or not.
    Regards,
    Swapnil K.

  • How to update XML file using XSLT

    Hi there,
    I have a "small" issue with exporting data to an XML file using XSLT.
    A two steps process is needed to import data from a non-hierarchical XML file into ABAP, change the data, and then update the XML file with new values. The problem is not trivial, since the format of the XML file is a complex one: there are many interdependent elements on the same level, pointing to each other by using id and ref attributes. Based on these values the data can be read and written into an internal table. I use XSLT and XPath for that. So the inbound process is done and seems to work correctly. I have to mention that the file contains much more data than I need. I am working only with a small part of it.
    Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT? I can pass only the internal table to the transformation, so how do I access the XML file in order to update it? I have tried to use the <B>xsl:document()</B> function to access the content of the file store locally on my PC, but it fails each time by throwing and URI exception. I have tried the absolute path without any addition and the path with the file:/// addition. Same result. Please advise.
    Many thanks,
    Ferenc
    P.S. Please provide me with links only if they are relevant for this very matter. I will not give points for irrelevant postings...

    Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT?
    XSLT approach:  check these online tutorial
    http://www.xml.com/pub/a/2000/08/02/xslt/index.html
    http://www.xml.com/pub/a/2000/06/07/transforming/index.html
    ABAP approach:
    for example you have the xml (original) in a string called say xml_out .
    data: l_xml  type ref to cl_xml_document ,
            node type ref to if_ixml_node  .
    create object l_xml.
    call method l_xml->parse_string
      exporting
        stream = xml_out.
    node = l_xml->find_node(
        name   = 'IDENTITY'
       ROOT   = ROOT
    l_xml->set_attribute(
        name    = 'Name'
        value   = 'Charles'
        node    = node
    (the above example reads the element IDENTITY and sets attribute name/value to the same)
    like wise you can add new elements starting from IDENTITY using various methods available in class CL_XML_DOCUMENT
    so how do I access the XML file in order to update it?
    you have already read this XML into a ABAP variable right?
    Sorry couldnt understand your whole process, why do you need to read local XML file?
    Raja

  • How to specify XML declaration in an XML Variable

    I had posted this question in the Flex Builder discussion,
    but I am not sure if that was the right board, so posting it again
    here:
    I need to set the XML declaration for my XML variable as
    follows:
    var employees:XML =
    <?xml version="1.0" encoding="utf-8"?>
    <employees>
    <employee ssn="123-123-1234">
    <name first="John" last="Doe"/>
    <address>
    <street>11 Main St.</street>
    <city>San Francisco</city>
    <state>CA</state>
    <zip>98765</zip>
    </address>
    </employee>
    <employee ssn="789-789-7890">
    <name first="Mary" last="Roe"/>
    <address>
    <street>99 Broad St.</street>
    <city>Newton</city>
    <state>MA</state>
    <zip>01234</zip>
    </address>
    </employee>
    </employees>;
    However, if I specify <?xml version="1.0"
    encoding="utf-8"?>, I get a design time and compile error. If I
    remove it it works fine. But the server to which I send this XML is
    expecting the declaration. How can I set the declaration?
    Any help or pointer is appreciated.

    I am not able to load the xml. Can anybody figure out the
    problem :
    I have used a LoadXML class :
    package {
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    // Demonstrates the code required to load external XML
    public class LoadXML extends Sprite {
    // The property that will eventually contain the loaded XML
    private var novel:XML;
    // The object used to load the XML
    private var urlLoader:URLLoader;
    // Constructor
    public function LoadXML () {
    // Specify the location of the external XML
    var urlRequest:URLRequest = new URLRequest("novel.xml");
    // Create an object that can load external text data
    urlLoader = new URLLoader();
    // Register to be notified when the XML finishes loading
    urlLoader.addEventListener(Event.COMPLETE,
    completeListener);
    // Load the XML
    urlLoader.load(urlRequest);
    // Method invoked automatically when the XML finishes
    loading
    private function completeListener(e:Event):void {
    // The string containing the loaded XML is stored in the
    URLLoader
    // object's data property (urlLoader.data). To create a new
    XML
    // instance from that loaded string, we pass it to the XML
    constructor
    novel = new XML(urlLoader.data);
    trace(novel.toXMLString()); // Display the loaded XML, now
    converted
    // to an XML object
    And in main.mxml :
    myXml = new LoadXml ;
    trace ( myXml.novel ) ;
    The output is errenous

  • Compare 2 XML Docs using JAXB

    Hello List,
    I use JAXB for parsing and generating XML docs. It works well after some time to learn to use it.
    But now I want compare 2 xml docs.
    I think the equal function is the right way, but I can't find any implementation from this function in the generated classes.
    Do I look right? Is it possible to compare xml docs with JAXB?
    Any other hints.
    regards Dietmar

    Earlier this year, I needed such a tool and finally wrote one after not being able to find one. It was a lot of work. It compared two DOM documents.
    In our case, we were testing a new server implementation to create XML result files from requests from our client. I connected to a new server and an old server and sent the identical input to both. I then validated the two results using DTD's (which is all we had) and then did a brute force comparison of the two Document objects.
    To make things more difficult, there were some known differences. The new version returned a few new tags and attributes in certain cases. I had to avoid using these as a reason to declare a mismatch. Also, there were timestamps and URLs returned in the files I was processing, so I had to ignore these tags as well.
    Another thing to consider is that attributes do not have to be presented in any sequence, so I had to compare in a non-order-specific way. I built two HashMaps, and first looked up each old attribute in the HashMap for new attributes. If I found a match, I removed this attribute from BOTH HashMaps, when I got to the end, anything lef t over in either HashMap was an orphan.
    It was a lot of work, and my solution is probably not usable outside of its environment, and I don't have permission to release the source anyway.
    Dave Patterson

  • How to read XML SpreadSheet using OleDb Provider

    Hi All,
    I have generated an xml spreadsheet (*.xls) using XSL. I have another program that reads this spreasheet and processes it.
    Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filnavn + ";" + "Extended Properties=Excel 8.0;"
    Dim objCon As OleDbConnection = New OleDbConnection(sConnectionString)
    objCon.Open()
    Dim objCmdSelect As OleDbCommand = New OleDbCommand("SELECT * FROM [General$]", objCon)
    Dim objAdapater As OleDbDataAdapter = New OleDbDataAdapter()
    objAdapater.SelectCommand = objCmdSelect
    Dim _DSGen As DataSet = New DataSet()
    objAdapater.Fill(_DSGen)
    I m facing an issue while opening a connection to the generated spreadsheet. It says "{"External table is not in the expected format."}".
    My Connection string is
    "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filnavn + ";" + "Extended Properties=Excel 8.0;"
    Do i need to change anything to this string ? I tried using a dataset and calling dataSet.ReadXml(excelFileName); But the dataset doesnt contain my table. Any inputs on how to read an xml spreadsheet ?
    How to read XML SpreadSheet in OleDb? How to Convert XML SpreadSheet to Microsoft Office Excel Sheet?
    Many Thanks

    Hi,
    You'lll most likely have better luck posting this in a Microsoft forum. This forum deals with issues specific to querying the Oracle database via the Oracle OLEDB provider.
    Cheers,
    Greg

  • Appending Data in XML File using JAXB

    I need to write the 50,000 records into XML file. But at a time i need to write only 1000 records into XML. How do i append the data into XML using JAXB.

    I have tried but the data is written in the following way:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Users xmlns="http://www.yyyy.com/umc/importer/jaxb">
    <User id="101" xmlns="">
    <username>gjhs</username>
    <password>hdfhhdf</password>
    <role>df</role>
    <email>sdd</email>
    <phone>sdfdf</phone>
    <description>shkl</description>
    <property name="ernnker" value="hkdfhk"/>
    </User>
    </Users>
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Users xmlns="http://www.yyyy.com/umc/importer/jaxb">
    <User id="101" xmlns="">
    <username>gjhs</username>
    <password>hdfhhdf</password>
    <role>df</role>
    <email>sdd</email>
    <phone>sdfdf</phone>
    <description>shkl</description>
    <property name="ernnker" value="hkdfhk"/>
    </User>
    </Users>
    If i can eliminate the following lines from the above files then my job is done:
    </Users>
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Users xmlns="http://www.yyyy.com/umc/importer/jaxb">

Maybe you are looking for