Writing xml file, midp, kxml - any ideas?

Hello,
Does any have sample code of writing an XML file with kXML or a similar tool?
I'm getting confused with OutputWriter being abstract/DataOutputWriters not working.
My code as follows is fairly non-existent..
OutputStream out = "test.xml"; // this errors with incompatible type (obviously) but what needs to go here?
XmlWriter fxml = new XmlWriter(out);
thanks in advance
poncenby

OutputStream out = "test.xml"this cant work. the latter is a string and the former an OutputStream.
yeah, thats pretty strange with the input and output of kXML. What you have to do is:
1) write a class, that extends the java.io.OutputStream. To do this, you have to implement all abstract methods of this (afaik write(byte))
2) this class can you pass to the XmlWriter. The most simple way of writing the bytes is to append it to a string, which you reference afterwards.
public class MyOutputStream extends OutputStream
public String output = "";
public void write(int b)
  output += (char)b;
}then write the stuff out and get the output of your OutputStream class. For writing this to a file (whichis not possible with J2ME, you have to some file handling in your OutputStream, like opening, appending and closing)
Note: this works only, if the content consists of characters. If you want to write binary data, this will get corrupt, since the cast to char transforms this binaries to characters. The reverse is (afaik) not possible.
hth
Kay

Similar Messages

  • "encoding = UTF-8" missing while writing XML file using file Adapter

    Hi,
    We are facing an unique problem writing xml file using file adapter. The file is coming without the encoding part in the header of xml. An excerpt of the file that is getting generated:
    <?xml version="1.0" ?>
    <customerSet>
    <user>
    <externalID>51017</externalID>
    <userInfo>
    <employeeID>51017</employeeID>
    <employeeType>Contractor</employeeType>
    <userName/>
    <firstName>Gail</firstName>
    <lastName>Mikasa</lastName>
    <email>[email protected]</email>
    <costCenter>8506</costCenter>
    <departmentCode/>
    <departmentName>1200 Corp IT Exec 8506</departmentName>
    <businessUnit>1200</businessUnit>
    <jobTitle>HR Analyst 4</jobTitle>
    <managerID>49541</managerID>
    <division>290</division>
    <companyName>HQ-Milpitas, US</companyName>
    <workphone>
    <number/>
    </workphone>
    <mobilePhone>
    <number/>
    </customerSet>
    </user>
    So if you see the header the "encoding=UTF-8" is missing after "version-1.0".
    Do we need to configure any properties in File Adapter?? Or is it the standard way of rendering by the adapter.
    Please advice.
    Thanks in advance!!!

    System.out.println(nodeList.item(0).getFirstChild().getNodeValue());

  • Writing XML files

    Hello all
    There's a vast amount of information on the java.sun.com site about parsing XML files:
    * creating DOM trees in memory from an XML file
    * setting up event handlers to be called when an XML file is parsed
    * transforming XML files using XSL.
    However, I can find very little information anywhere about writing XML files in the first place! I'm already aware of two ways to do this:
    (1) create a DOM in memory and write this to a file. If the data is large, though, this isn't feasible.
    (2) just output the XML elements directly to some file as text. This doesn't take account of the encoding, or special characters, and the document is not necessarily then syntactically valid.
    Is there some API which I haven't yet come across that is designed specifically for writing XML data to files? If it's built in to Java 2, then goodness knows how I've missed it all this time; if it's third-party, I'd be grateful for any links.
    Thanks for your help
    Rich Fearn

    I know pastes can be horrible, but this is a working example which I find useful: SAX XML output ;)
    import java.io.*;
    // SAX classes.
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    //JAXP 1.1
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.*;
    import javax.xml.transform.sax.*;
                    //AlphabetXMLOut(file, alphabets);
    class AlphabetXMLOut {
            public void run(){
                    try{
                            FileOutputStream fos = new FileOutputStream("output.xml");
                            PrintWriter out = new PrintWriter(fos);
                            StreamResult streamResult = new StreamResult(out);
                            // PrintWriter from a Servlet
                            //PrintWriter out = response.getWriter();
                            //StreamResult streamResult = new StreamResult(out);
                            SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
                            // SAX2.0 ContentHandler.
                            TransformerHandler hd = tf.newTransformerHandler();
                            Transformer serializer = hd.getTransformer();
                            serializer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
                            serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"users.dtd");
                            serializer.setOutputProperty(OutputKeys.INDENT,"yes");
                            hd.setResult(streamResult);
                            hd.startDocument();
                            AttributesImpl atts = new AttributesImpl();
                            // USERS tag.
                            hd.startElement("","","USERS",atts);
                            // USER tags.
                            String[] id = {"PWD122","MX787","A4Q45"};
                            String[] type = {"customer","manager","employee"};
                            String[] desc = {"Tim@Home","Jack&Moud","John D'oe"};
                            for (int i=0;i<id.length;i++){
                                    atts.clear();
                                    atts.addAttribute("","","ID","CDATA",id);
    atts.addAttribute("","","TYPE","CDATA",type[i]);
    hd.startElement("","","USER",atts);
    hd.characters(desc[i].toCharArray(),0,desc[i].length());
    hd.endElement("","","USER");
    hd.endElement("","","USERS");
    hd.endDocument();
    fos.close();
    }catch (IOException e){
    System.err.println ("Unable to write to file");
    System.exit(-1);
    }catch (TransformerConfigurationException tce){
    System.err.println("Error in: TransformerConfigurationException");
    }catch (SAXException spe) {
    // Error generated by the parser
    System.err.println("Error in: (SAXException");
    // Use the contained exception, if any
    Exception x = spe;
    if (spe.getException() != null)
    x = spe.getException();
    x.printStackTrace();
    -Hope this helps

  • I'm getting a 9041 error when trying to convert files to AAC -- any ideas on how to fix it?  the files files in iTunes show up as Apple Lossless but i can't put them on my iPod

    i'm getting a 9041 error when trying to convert files to AAC -- any ideas on how to fix it?  the files files in iTunes show up as Apple Lossless but i can't put them on my iPod

    "I have been able to convert to AAC by first converting to AIFF  and then to AAC. This is a pan though."
    this worked for me.
    thanks.

  • I purchased a album and only the first part of each song plays, even though the entire length is listed  in the file properities. Any Ideas?

    I purchased a album and only the first part of each song plays, even though the entire length is listed  in the file properities. Any Ideas?

    Assuming you are in a region where you are allowed to redownload your past purchases, delete the current copies from your iTunes library and then download again from your purchased history. If the problem persists, or that facility is not available in your region, contact the iTunes Store support staff through the report a problem links in your account history.
    tt2

  • Bought Canon FS400 videocam with digital storage.  iPhoto says cannot recognize the file format.  Any ideas?  Thanks so much!

    Bought Canon FS400 videocam with digital storage.  Tried to import, but iPhoto says cannot recognize the file format.  Any ideas?  Thanks so much!

    Can you access the material with iMovie?

  • Scanning in both HP Officejet 7210 and Samsung printer - the document scans but no file is generated - any ideas how to fix this?  (It worked fine before installing Mavericks)

    Scanning in both HP Officejet 7210 and Samsung printer - the document scans but no file is generated - any ideas how to fix this?  (It worked fine before installing Mavericks)

    PS: forgot to mention: if your printer is on your wifi network, you'll have to enter your wifi password on the printer to connect it to the network before Printers & Scanners will see it.
    Sometimes a reset of the wifi system is needed too. A full set of directions would be:
    Try:
    uninstall all printer manufacturer apps and "utilities"
    go to System Preferences > Printers & Scanners > Print
    control-click on your printer in the column on the left
    select "Reset Printing System..." and "reset" in the dialog that follows
    do a factory reset on your printer. You'll have to consult the printer manual for how.
    power down everything: modem, router, computer, and printer
    power up each item in turn in the same order: modem, router, computer, and printer. Let each power up completely before moving on to the next
    enter your wifi password in your printer so it can connect to the network
    go back to printers & scanners and it should see your printer and download a driver for it from Apple
    resist the temptation to install any printer manufacturer apps in the future.

  • Writing XML file

    Hi I am trying to create an xml file in the following manner:
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.apache.xerces.dom.DocumentImpl;
    import org.apache.xerces.dom.DOMImplementationImpl;
    import org.apache.xml.serialize.*;
    import java.io.File;
    import java.io.StringWriter;
    import java.io.FileOutputStream;
    public class XMLData {
    public void createXML(){
    Element e = null;
    Node n = null;
    Document xmldoc= new DocumentImpl();
    Element root = xmldoc.createElement("USERS");
    String[] id = {"PWD122","MX787","A4Q45"};
    String[] type = {"customer","manager","employee"};
    String[] desc = {"Tim@Home","Jack&Moud","John D'o�"};
    for (int i=0;i<id.length;i++)
      e = xmldoc.createElementNS(null, "USER");
      e.setAttributeNS(null, "ID", id);
    e.setAttributeNS(null, "TYPE", type[i]);
    n = xmldoc.createTextNode(desc[i]);
    e.appendChild(n);
    root.appendChild(e);
    xmldoc.appendChild(root);
    try{
         File f= new File(XMLData.class.getResource("/utilities/config.xml").toURI());
         FileOutputStream fop= new FileOutputStream(f);
    OutputFormat of = new OutputFormat("XML","ISO-8859-1",true);
    of.setIndent(1);
    of.setIndenting(true);
    XMLSerializer serializer = new XMLSerializer(fos,of);
    serializer.asDOMSerializer();
    serializer.serialize( xmldoc.getDocumentElement() );
    fos.close();
    catch(Exception ex)
    System.out.println(ex.getMessage():
    the problem that I'm getting is that nothing is being written to the file, and therefore it is not being created.
    Can someone point out what I'm doing wrong. I suppose its quite a trivial thing...
    Thanks

    No, it does not solve the problem...It could be due to this line of code though:
    File f= new File(XMLData.class.getResource("/utilities/config.xml").toURI());any ideas about whether this is correct or not...cause if I just use :
    File f = new File("config.xml"); the output is generated and the file is created though it is not placed in the correct directory.
    thanks
    Message was edited by:
    cicho_41

  • Writing xml file to my pc

    I have a stored procedure that creates xml data from a query.I can put this xml file onto the oracle server where the query runs from.Im using the utl_file package for this. But I want to put this xml file(well it will be a HL7 extension) into a specified folder on my desktop.
    Anybody have any ideas how best to approach this?Thanks

    Have you got code to do this?Is the is the only way of doing this,I have an interface engine on my machine,which is why I want to put the file onto my machine so the interface engine can see it.

  • Writing XML file using javax.xml package

    I am writing an XML file with the foll piece of code:
    public static void writeXmlFile(Document doc, String filename) {
    try {
    // Prepare the DOM document for writing
    Source source = new DOMSource(doc);
    // Prepare the output file
    File file = new File(filename);
    Result result = new StreamResult(file);
    // Write the DOM document to the file
    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    xformer.transform(source, result);
    } catch (TransformerConfigurationException e) {
    } catch (TransformerException e) {
    In this case above, the whole Document has to be passed to create a new DOMSource. is there any way where in I can pass the individual Nodes to the DOMSource ?
    I want the Nodes to be written one by one as writing the whole document is giving me a OutOfMemoryError (I have about a million records to be written in the XML file).
    Any help would be greatly appreciated

    I am writing an XML file with the foll piece of code:
    public static void writeXmlFile(Document doc, String filename) {
    try {
    // Prepare the DOM document for writing
    Source source = new DOMSource(doc);
    // Prepare the output file
    File file = new File(filename);
    Result result = new StreamResult(file);
    // Write the DOM document to the file
    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    xformer.transform(source, result);
    } catch (TransformerConfigurationException e) {
    } catch (TransformerException e) {
    In this case above, the whole Document has to be passed to create a new DOMSource. is there any way where in I can pass the individual Nodes to the DOMSource ?
    I want the Nodes to be written one by one as writing the whole document is giving me a OutOfMemoryError (I have about a million records to be written in the XML file).
    Any help would be greatly appreciated

  • Writing XML Files in Java

    Hi,
    How do I WRITE to XML Files.I know parsing is for reading but what is for writing?
    Thankx in advance...

    JAXP1.1 can be used for parsing the XML file to read/write from/to XML file.A node can be created or any node Value can be updated or changed using XML parser.Using TransformerFactory and Transformer class one can write back to any XML file.
    If U still want any help write back to me.
    Thanx

  • "PLS-00172: string literal too long" When Writing XML file into a Table

    Hi.
    I'm using DBMS_XMLStore to get a XML file into a db table. See the example below, I'm using that for my PL/SQL format. Problem is that because there're too many XML elements that I use in "xmldoc CLOB:= ...", I get "PLS-00172: string literal too long" error.
    Can someone suggest a workaround?
    THANKS!!!
    DECLARE
    insCtx DBMS_XMLStore.ctxType;
    rows NUMBER;
    xmldoc CLOB :=
    '<ROWSET>
    <ROW num="1">
    <EMPNO>7369</EMPNO>
    <SAL>1800</SAL>
    <HIREDATE>27-AUG-1996</HIREDATE>
    </ROW>
    <ROW>
    <EMPNO>2290</EMPNO>
    <SAL>2000</SAL>
    <HIREDATE>31-DEC-1992</HIREDATE>
    </ROW>
    </ROWSET>';
    BEGIN
    insCtx := DBMS_XMLStore.newContext('scott.emp'); -- get saved context
    DBMS_XMLStore.clearUpdateColumnList(insCtx); -- clear the update settings
    -- set the columns to be updated as a list of values
    DBMS_XMLStore.setUpdateColumn(insCtx,'EMPNO');
    DBMS_XMLStore.setUpdateColumn(insCtx,'SAL');
    DBMS_XMLStore.setUpdatecolumn(insCtx,'HIREDATE');
    -- Now insert the doc.
    -- This will only insert into EMPNO, SAL and HIREDATE columns
    rows := DBMS_XMLStore.insertXML(insCtx, xmlDoc);
    -- Close the context
    DBMS_XMLStore.closeContext(insCtx);
    END;
    /

    You ask where am getting the XML doc. Well, am not
    getting the doc itself.I either don't understand or I disagree. In your sample code, you're certainly creating an XML document-- your local variable "xmldoc" is an XML document.
    DBMS_XMLSTORE package needs
    to know the canonical format and that's what I
    hardcoded. Again, I either don't understand or I disagree... DBMS_XMLStore more or less assumes the format of the XML document itself-- there's a ROWSET tag, a ROW tag, and a then whatever column tags you'd like. You can override what tag identifies a row, but the rest is pretty much assumed. Your calls to setUpdateColumn identifies what subset of column tags in the XML document you're interested in.
    Later in code I use
    DBMS_XMLStore.setUpdateColumn to specify which
    columns are to be inserted.Agreed.
    xmldoc CLOB :=
    '<ROWSET>
    <ROW num="1">
    <KEY_OLD> Smoker </KEY_OLD>
    <KEY_NEW> 3 </KEY_NEW>
    <TRANSFORM> Specified </TRANSFORM>
    <KEY_OLD> Smoker </KEY_OLD>
    <VALUEOLD> -1 </VALUEOLD>
    EW> -1 </VALUENEW>
         <DESCRIPTION> NA </DESCRIPTION>
    </ROW>
    ROWSET>';This is your XML document. You almost certainly want to be reading this from the file system and/or have it passed in from another procedure. If you hard-code the XML document, you're limited to a 32k string literal, which is almost certainly causing the error you were reporting initially.
    As am writing this I'm realizing that I'm doing this
    wrong, because I do need to read the XML file from
    the filesystem (but insert the columns
    selectively)...What I need to come up with is a proc
    that would grab the XML file and do inserts into a
    relational table. The XML file will change in the
    future and that means that all my 'canonical format'
    code will be broken. How do I deal with anticipated
    change? Do I need to define/create an XML schema in
    10g if am just inserting into one relat. table from
    one XML file?What does "The XML file will change in the future" mean? Are you saying that the structure of the XML document will change? Or that the data in the XML document would change? Your code should only need to change if the structure of the document changes, which should be exceptionally uncommon and would only be an issue if you're adding another column that you want to work with, which would necessitate code changes.
    I found an article where the issue of changing XML
    file is dealt by using a XSL file (that's where I'd
    define the 'canonical format'), but am having a
    problem with creating one, because the source XML is
    screwed up in terms of the format:
    it's not <x> blah </x>
    <x2> blah </x2>
    x2="blah" x3="blah> ...etc
    Can you point me in the right direction, please?You can certainly use something like the DBMS_XSLProcessor package to transform whatever XML document you have into an XML document in an appropriate format for the XMLStore package and pass that transformed XML document into something like your sample procedure rather than defining the xmldoc local variable with a hard-coded document. Of course, you'd need to write appropriate XSL code to do the actual transform.
    Justin

  • I did the update to 3.6.11 - when it restarted it will not open any pages. When i go to check for updates it gives me this error: Update XML file malformed (200) - Any advice?

    I did the update to 3.6.11 - After it started Firefox it would go to the requested site in the addressbar, but the page would be blank. I went to check for updates and it told me there was a problem in updating. It gave me this error message: Update XML file malformed (200)
    I uninstalled and reinstalled and the same problem exists.
    Any advice?

    For the error message see [[AUS Update XML File Malformed 200]].
    As it appears not to be able to load any sites, a possible cause is your firewall blocking the new version of Firefox. For more details see [[Firefox cannot load websites but other programs can]].

  • Copying files to my MBA Early 2011, 10.6.7 changes their 'date modified' to the current date. It happens only to some of the files copied. Any idea what my be causing it. Never had this problem before, on othe macs I have owned.

    Copying files to my new MBA (early 2011) running 10.6.7 results in their 'modification date' to change to the current date. Any idea what may be causing it. It happens only to some of the files (there is no pattern to it.). I have not seen it previously in many other macs I have owned.

    Hi all
    I am bumping this thread again because I can't believe that I am the only one experiencing this issue. At times it is costing me hours repeatedly copying files until eventually the date doesn't show as modified.
    I thought I had cracked it earlier by changing the Sharing & Permissions settings, and applying to enclosed items the ability for Everyone, Me and Staff fo have Read & Write permissions - but that doesn't seemed to have changed much.
    Copying in smaller batches helps sometimes, but then other times it makes no odds, and the Date Modified date shows as the original date for a few seconds, only to change to today's date. Driving me nuts because there is no pattern to it.
    Files which I have copied and show their original modified date, when moved to a subfolder, then have their date changed to today!!! Copying other files into the folder results in files that were previously OK having their Date Modified changed!
    Am I on the only one?

  • Writing XML files using file adapter

    Hi All,
    I am using Oracle file adapter to write xml files, I am poinitng it to an xsd while specifying schema.The XML files are getting generated with target namespace information and name space prefixes in the xml data elements. I have a specific requirement to create xml files without any namespace/name space prefix tags in it. Can we acheive it using file adapter?
    otherwise is there anyother way of doing this in bpel.
    Any suggestions are welcome.
    Thanks

    What is the name you have entered in sender channel, if you have entered.pdf only it process PDF files. select option skip empty file option in sender channel and enter name ..
    most probably this issue coming with empty files.

Maybe you are looking for

  • Deauthorizing computers that no longer exist.

    How do you deauthorize a itunes system on a computer that no longer exists.   I have replaced computers and did not deauthorize them before discarding.  I cannot authorize new systems because of the 5 system limitation in itunes.   I want to use home

  • Facebook will not boot up on my iPad but works on my iPhone ??  Please help

    MY Facebook app has not been able to boot up on my iPad since Thursday. It works fine on my iPhone but I just get a blank white screen with a blue border across the header. After a few seconds it just goes back to iPad menu. I have deleted an re inst

  • Setting Expiration period for Maintenance Plan Backups fails to work in sql server 2008

    I have created a Maintenance Plan to do a nightly full backup and set the backup set to expire after 4 days in sql server 2008 R2. Weeks later, old backups are sitting on the hard drive.Please do the needful.

  • Store item document in DMS

    Hi, We have cProject documents  linked to DMS (different systems). Now we need when a document is created at item level is stored in DMS ( different systems). Is it possible? Thanks, Sara

  • Aperture 3 Not Working at all

    I have briefly scanned these post but don't see anyone saying ***. I have just updated to Aperture 3 and my system has crashed several times already and when its not crashing it is virtually unusable. I am on a MacBookPro 2.16 running 10.5.8. I had n