Appending XML file

Can somebody help me?
I have a program that creates an XML file but every time I run the program I want that file to be appended. I can append the file but with XML I need to append the file before the final closing tag.
This is my code:
<%@page contentType="text/html"%>
<html>
<head>
<basefont face="Arial">
</head>
<body>
<%@ page language="java" import="java.io.*" %><%
%><%@taglib uri="/WEB-INF/taglib65.tld" prefix="go"%>
<%@taglib uri="/WEB-INF/filetags.tld" prefix="file"%>
<form method=GET action="output.jsp">
<%
String xposition = request.getParameter("position");
String ynflteam = request.getParameter("nflteam");
String zplayer = request.getParameter("player");
%>
<%
if(xposition.equals("position")){
%>
<go:Back alert="Please Select The Player's Position!"/>
<%
}else if(ynflteam.equals("nflteam")){
%>
<go:Back alert="Please Select The Player's NFL Team!"/>
<%
%>
<file:writeFile source="c:\\nfl.xml" append="true">
<fantasyteam>
<position><%= xposition %></position>
<nflteam><%= ynflteam %> </nflteam>
<playername><%= zplayer%></playername>
</fantasyteam>
</file:writeFile>
<%
out.println("Player: " zplayer " has been added to your team");
%>
<br><br>
<input type="Submit" value="Continue">
</FORM>
</form>
</body>
</html>
It creates the XML file but when I go to add another entry and view the file it won't display because the file was closed by the previous entry.
Eg:
<fantasyteam>
<position>RB</position>
<nflteam>New York Jets</nflteam>
<player>Curtis Martin</player>
</fantasyteam> ----- HERE THE XML FINISHES
<fantasyteam> ---- HERE IS ANOTHER ENTRY BUT IT WON'T WORK DUE TO THE CLOSING </fantasyteam> TAG!
<position>WR</position>
<nflteam>New York Jets</nflteam>
<player>Santana Moss</player>
</fantasyteam>
What I want the file to look like is:
<fantasyteam>
<position>RB</position>
<nflteam>New York Jets</nflteam>
<player>Curtis Martin</player>
<position>WR</position>
<nflteam>New York Jets</nflteam>
<player>Santana Moss</player>
</fantasyteam>
Can anyone help?
Thanks
Michael

Hi,
I think there are two ways. When using DOM in your file:write-method, you must parse the old file, add th enew nodes and then write the change document in the file. By the other way, without DOM, read the old file in a StringBuffer, delete the end with String-operations, append your new nodes as String, also the close-tag and wirte the change StingBuffer in the file.
Hope thats help.
Roland

Similar Messages

  • Append xml elements to a file

    Ok. After solve the problem of append to files using a file adapter in osb (Re: Write/Append text file with OSB now i want to know if there is some way to append elements to an existant xml. For each request i will have the following message:
    <root_node>
    <msg>
    <element />
    <element />
    <inner>
    <inner_data />
    </inner>
    <inner>
    <inner_data />
    </inner>
    <msg>
    </root_node>
    And, for two requests ai want to log:
    <root_node>
    <msg>
    <element />
    <element />
    <inner>
    <inner_data />
    </inner>
    <inner>
    <inner_data />
    </inner>
    <msg>
    <msg>
    <element />
    <element />
    <inner>
    <inner_data />
    </inner>
    <inner>
    <inner_data />
    </inner>
    <msg>
    </root_node>
    And no:
    <root_node>
    <msg>
    <element />
    <element />
    <inner>
    <inner_data />
    </inner>
    <inner>
    <inner_data />
    </inner>
    <msg>
    </root_node>
    <root_node>
    <msg>
    <element />
    <element />
    <inner>
    <inner_data />
    </inner>
    <inner>
    <inner_data />
    </inner>
    <msg>
    </root_node>
    As i'm doing (in my tests).
    Thank you.

    do you want to append/insert nodes in the file
    or do you want to construct that xml first in the osb and after that insert the xml in the file ?
    http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/modelingmessageflow.html
    Message Processing Actions
    Insert activity
    you can use the insert activity to insert/append xml parts in your payload, and when the format is done, write it to the file

  • How I can append new node in existing  XML file

    I've just begun learning DOM XML , so I'm currently at a very beginner level.
    I have an existing XML file that I would like to add an additional node to before saving it to another variable.
    how I can append new node in this file.
    now this code is overwrite new data over old data
    The code looks like this:
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.Result;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.TransformerFactoryConfigurationError;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Attr;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    public class VerbXMLWriter
        static String EVerb3;
        static String englishTranslate3;
        public void VerbXMLWriter(String EVerb, String englishTranslate )
             EVerb3 = EVerb;
             englishTranslate3=englishTranslate;
        File xmlFile = new File("VerbDB.xml");
        DocumentBuilderFactory factory =  DocumentBuilderFactory.newInstance();
        try
         DocumentBuilder builder = factory.newDocumentBuilder();
         Document document = builder.newDocument();
        Element root = document.createElement("Verb");
         document.appendChild(root);
         Element verb = document.createElement(EVerb3);
         verb.setAttribute("EnglishTranslate",englishTranslate3);
         root.appendChild(verb);
         Source xmlSource = new DOMSource( document );
         Result result = new StreamResult( new FileOutputStream(xmlFile) );
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer =
        transformerFactory.newTransformer();
        transformer.setOutputProperty( "indent", "yes" );
         transformer.transform( xmlSource, result );
      catch(TransformerFactoryConfigurationError factoryError )
        factoryError.printStackTrace();
       catch (ParserConfigurationException pc)
           pc.printStackTrace();
       catch (IOException io)
          io.printStackTrace();
       catch(Exception excep )
           excep.printStackTrace();
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <Verb>
    <Play EnglishTranslate="playing" />
    </Verb>Edited by: itb402 on Mar 9, 2008 6:05 AM

    in your code you are already appending new nodes to the root node. so what exactly is your problem? The following steps are usually taken for appending a new node:
    1. Read the XML document
    2. Build a DOM tree
    3. Navigate to the node under which you want to insert the new node
    4. Create a new node.
    5. Insert the new node to the node selected in point #3.
    ~Debopam

  • Appending content to an XML file in the Root tag using FileAdapter

    Hi Friends..!!
    I have got a requirement like this. There will be an XML file with List of Employees like following...
    <Employees>
    <Emp>
    <SNo>111</Sno>
    <Fname>Mahesh<Fname>
    <Lname>Babu</Lname>
    </Emp>
    <Emp>
    <SNo>222</Sno>
    <Fname>----<Fname>
    <Lname>-----</Lname>
    </Emp>
    <Emp>
    <SNo>----</Sno>
    <Fname>----<Fname>
    <Lname>----</Lname>
    </Emp>
    </Employees>
    .. So What i have to do is Appending the given Employees info to the existed XML file using File Adapter. But When i m trying to figure it out.. the given details are appended at the end of the previous content.. but i want to see all the Emp tags(the newly appended emp list also) in the existed <Employees> tag only..
    (i m also facing namespace issues here)
    Can u plz provide solution for this problem..?
    Thanks in advance.
    Regards-
    Nlion7

    Hi Nilon7,
    the given details are appended at the end of the previous contentThat will be the behaviour if you are just using file write with append...
    You will need to expand your solution into three steps, firstly a file adapter sync read to retrieve the current contents of the file, then a xslt transformation to "merge" the current data with the new data and finally a file adapter write with the merged content...
    Cheers,
    Vlad

  • Appending multiple xml files to single xml file using File channel?

    Hi Experts,
    I would like to get some pointers around xml files append.
    My sender application will send around 1000 messages through SOAP per day. But the target application needs single xml file formed by consolidation of all these 1000 files.
    I tried with txt files and the receiver file channel could append the txt files. However, since xml files allow only one root node, I am not able to achieve the requirement.
    Is there any option we can do to get the result?
    The target file location is UNIX folder. Do we need to create any shell script to run from the channel for appending the file?
    Do we need to use any XSLT mapping to strip the xml declaration tags and append the files. Once the single file is ready, using another file channel with XSLT mapping, insert a dummy root node and xml declaration tags to build an xml file?
    Any thoughts to get the result will be much appreciated.
    Thanks
    Ray..

    Hi,
    You have two options
    1)Using Receiver Sender File channel select mode append it does the job.
    Option 2:
    Using BPM we cann collect all messages per day and club them as a one message, in this case create Target data type root node occurance 1 to unbounded. so it cal hold multiples SOAP messages in only XML messages.
    search in sdn for BPM collect pattrersn,its very simple .
    Option 3:
    Create scheell script in OS level and write a logic to append all files planced in FTP.
    Regards,
    Raj

  • Appended log files are not well formed XML?

    I'm working on a retrofit of our home grown logging class to use the new java.util.logging classes. It works beautifully with one exception. If I need to instantiate the logger in the same day, appending to an existing log file, I get a second (or third, or fourth) <?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE log SYSTEM "logger.dtd"> tag inserted at the beginning of the new log entries. This causes the log file to not be well formed and therefore cannot be parsed.
    I've looked and looked, but can't find a method to suppress these extra tags. Anybody know a way? We want to use this on a development server that will be restarted several times a day. If I don't append, it wipes out my previous logs for the day.

    You'll have to do something to prevent your logger from appending to old logs that have been closed. Sorry if that is not very helpful, but I'm not familiar with the logging features in SDK 1.4. For your interest, though, Log4J (which you can get from Apache) also features XML logging, and it solved that rather obvious problem thus:
    "The output of the XMLLayout consists of a series of log4j:event elements as defined in the log4j.dtd. It does not output a complete well-formed XML file. The output is designed to be included as an external entity in a separate file to form a correct XML file."
    In other words, you would have to wrap the output in an XML header and a root node to be able to use it, which is not difficult to do.

  • 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">

  • To append tasks to an Microsoft XML file format i,e MSPDI using MPXJ.

    I have used the below mentioned code.But with this code, The new task is not appending in the proper Order.. i,e the newly added Major task gets inserted after the first major task. instead of getting added after the last task.
    can anyone help me to solve the above mentioned issue.
    import java.io.PrintStream;
    import java.text.SimpleDateFormat;
    import net.sf.mpxj.*;
    import net.sf.mpxj.mpp.MPPReader;
    import net.sf.mpxj.mpx.MPXReader;
    import net.sf.mpxj.mpx.MPXWriter;
    import net.sf.mpxj.mspdi.*;
    import net.sf.mpxj.mspdi.MSPDIWriter;
    import net.sf.mpxj.utility.NumberUtility;
    import net.sf.mpxj.writer.ProjectWriter;
    public class CreateXML
    public CreateXML ()
    public static void main(String args[])
    try
    create("d:\\output.XML");
    catch(Exception ex)
    ex.printStackTrace(System.out);
    private static ProjectWriter getWriter(String filename)
    String suffix;
    if(filename.length() < 4)
    suffix = ".MPX";
    else
    suffix = filename.substring(filename.length() - 4).toUpperCase();
    ProjectWriter result;
    if(suffix.equals(".XML"))
    result = new MSPDIWriter();
    else
    result = new MPXWriter();
    return result;
    private static void create(String filename)
    throws Exception
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    MSPDIReader r=new MSPDIReader();
    ProjectFile file=r.read("d:\\input.XML");
    file.setAutoTaskID(true);
    file.setAutoTaskUniqueID(true);
    file.setAutoResourceID(true);
    file.setAutoResourceUniqueID(true);
    file.setAutoOutlineLevel(true);
    file.setAutoOutlineNumber(true);
    file.setAutoWBS(true);
    file.setAutoCalendarUniqueID(true);
    ProjectCalendar calendar = file.addDefaultBaseCalendar();
    ProjectCalendarException exception = calendar.addCalendarException();
    exception.setFromDate(df.parse("13/06/2007"));
    exception.setToDate(df.parse("13/06/2007"));
    exception.setWorking(false);
    ProjectHeader header = file.getProjectHeader();
    header.setStartDate(df.parse("1/06/2007"));
    Resource resource1 = file.addResource();
    resource1.setName("Resource1");
    Resource resource2 = file.addResource();
    resource2.setName("Resource2");
    resource2.setMaxUnits(new Double(50D));
    Task task1 = file.addTask();
    task1.setName("Main Task2");
    task1.setStart(df.parse("12/07/2007"));
    task1.setDuration(Duration.getInstance(100D, TimeUnit.DAYS));
    Task task2 = task1.addTask();
    task2.setName("T13");
    task2.setDuration(Duration.getInstance(5, TimeUnit.DAYS));
    task2.setStart(df.parse("6/10/2007"));
    task2.setPercentageComplete(NumberUtility.getDouble(50D));
    ProjectWriter writer = getWriter(filename);
    writer.write(file, filename);
    }

    so, I got that working, and then when I tried to repeat for another text field on another timeline frame, I get the message:
    Scene 1, Layer 'TEXT', Frame 62, Line 6
    1021: Duplicate function definition.
    here's the code:
    var restaurant:URLLoader = new URLLoader();
    restaurant.EventListener(Event.COMPLETE, onLoaded);
    function onLoaded(e:Event):void {
    restauranttxt.text = e.target.data;
    myTextLoader.load(new URLRequest("editable/restaurant.txt"));
    so the error is coming on line 6, which is the function onLoaded line.
    I tried renaming onLoaded in the listener and here to "restaurant", even to "onLoaded 2".  when I do that, my movie goes haywire.  it either gets to frame 16 and stops (a frame that contains a mouse click goto and stop event handler to go to this frame), or, none of the timeline stop(): actions work.
    I feel like I'm so close to understanding.  I guess I just don't understand the part that makes it go haywire if I change the names.

  • Comparing an excel file to and xml file and appending data to the xml file

    I have an xml file (mapsource) and an excel file. One of the columns in the excel file matches up with a node in the xml file. I want to be able to loop through both files and add a new node to the xml file where the one of the columns in the excel file matches a node in the xml file.
    I can create a query object out of the excel dosument using the cfspreadsheet tag.
    I'm able to use xmlparse to create a xml document object from the xml file.
    What I would like to do is add col_3 from the excel spreadsheet as a new node when col_2 is equal to gpx.wpt.name.xmltext of the xml object.
    Any help or direction would be very helpful!

    Hi,
    Thank you for your reply. But I have to attach an excel file from a particular path (C:\TEMP\TEST.XLS) and I have to send that excel file to the user inbox.That excel file has multiple sheets with data. Can you please provide me any code is available.
    Thanks and Regards
    venkat.

  • Append an element to the original xml file

    Guys,
    I have the original xml file.
    Can i add some element, i mean child node, to that file?
    if so could anyone tell me please.
    currently i'm using JDOM to process XML thing.
    Many Thanks :)
    Ty

    Im having trouble with writting to the actuall file too. I can scan xml and find nodes and attributes that I want to change, I change them, and it seems to work because if I get them with like element.getAttribute I can see the value I just set, but the file hasent changed a bit. Good luck with the solution, if you find one can you post it here, I'd be so gratefull...Cheers.

  • How do i update an existing XML File?

    Hello, I have the following xml file gps.xml:<?xml version="1.0"?>
    <!DOCTYPE gps SYSTEM "gps.dtd">
    <gps>
       <latitude>43.00000</latitude>
       <longitude>-83.00000</longitude>
    </gps> I already have methods written to get the values. But how can I change these values and update the file to reflect these changes?
    thanks for your help!

    Hi, I already have this following code. I would just like to add a method to it to update the existing XML file with different lat/lon coordinates. Could you please help me out with it? thanks
    import java.io.*;
    import java.io.PrintWriter;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    public class Gps implements java.io.Serializable {
        private double latitude_;
        private double longitude_;
        public Gps(Document doc) {
            setup(doc.getDocumentElement());
        public Gps(String uri) throws IOException, SAXException, ParserConfigurationException {
            setup(uri);
        public void setup(Document doc) {
            setup(doc.getDocumentElement());
        public void makeElement(Node parent) {
            Document doc;
            if (parent instanceof Document) {
                doc = (Document)parent;
            } else {
                doc = parent.getOwnerDocument();
            Element element = doc.createElement("gps");
            int size;
            URelaxer.setElementPropertyByDouble(element, "latitude", this.latitude_);
            URelaxer.setElementPropertyByDouble(element, "longitude", this.longitude_);
            parent.appendChild(element);
         public Document makeDocument() throws ParserConfigurationException {
            Document doc = UJAXP.makeDocument();
            makeElement(doc);
            return (doc);
        public final double getLatitude() {
            return (latitude_);
        public final void setLatitude(double latitude) {
            this.latitude_ = latitude;
        public final double getLongitude() {
            return (longitude_);
        public final void setLongitude(double longitude) {
            this.longitude_ = longitude;
       public final void updateXmlFile(double latitude, double longitude) {
         // something???
        public final void updateXmlFile(double latitude, double longitude) {
            this.latitude_ = latitude;
            this.longitude_ = longitude;
        public String makeTextDocument() {
            StringBuffer buffer = new StringBuffer();
            makeTextElement(buffer);
            return (new String(buffer));
        public void makeTextElement(StringBuffer buffer) {
            int size;
            buffer.append("<gps");
            buffer.append(">");
            buffer.append("<latitude>");
            buffer.append(Double.toString(getLatitude()));
            buffer.append("</latitude>");
            buffer.append("<longitude>");
            buffer.append(Double.toString(getLongitude()));
            buffer.append("</longitude>");
            buffer.append("</gps>");
        public String toString() {
            try {
                return (makeTextDocument());
            } catch (Exception e) {
                return (super.toString());
    }

  • ABAP to XML file - Formatting problem and UTF-8 requirement

    Hi Everyone,
    Could you please guide us on the ABAP coding required to get the proper XML file format. We have prepared the code for downloading SAP transaction data into an XML file format. However, we are stuck with an improper format as per Example 1.
    The file format we get is this:
    Example 1:
    <?xml version="1.0"?><FDXLMDOrd><FXNHdrLp><CrtDtTm>20070613094517</CrtDtTm><MsgID>319304155</MsgID><MsgTyp>850</MsgTyp><MsgSubTyp>SALES_A</MsgSubTyp><Pr
    <RcvTP>FSCS</RcvTP><SndSrc>FXN</SndSrc><RcvSrc>EIB</RcvSrc><UsrID>VAR</UsrID></FXNHdrLp><OrdHdrLp><OrdNbr>319304155</OrdNbr><OrdActnCD>9</OrdActnCD><Ord
    teCarrReq>FDE</RteCarrReq><RteTptSvcReq>FEIP</RteTptSvcReq></DprtRteLp><SpecInstrLp><SpecInstrTyp>SHIP</SpecInstrTyp><SpecInstr>Example Packing Instruct
    les Order</RefDesc></RefLp><RefLp><RefIDQual>CPO</RefIDQual><RefID>test 1 line 1 pc - s</RefID><RefDesc>Customers Customer Purchase Order</RefDesc></Ref
    Typ><EntIDQual>91</EntIDQual><EntID>H00092</EntID><EntNm>VLAD BOBES</EntNm><Cty>MONTREAL</Cty><PstlCD>H3X 2N5</PstlCD><RgnalCD>QC</RgnalCD><CtryISOCD>CA
    ></AdrLnLp><ConLp><ConTypCD>IC</ConTypCD><ConNm>VLAD BOBES</ConNm><CommLp><CommNbrQual>TE</CommNbrQual><CommNbr>514-731-8361</CommNbr></CommLp></ConLp><
    <Cty>MONTREAL</Cty><PstlCD>H3X 2N5</PstlCD><RgnalCD>QC</RgnalCD><CtryISOCD>CA</CtryISOCD><AddlNmLp><AddlNm1>VLAD BOBES</AddlNm1></AddlNmLp><AdrLnLp><Str
    However, the format need to look like this as in Example 2 below.
    We also need help in how to get  " encoding="UTF-8"?> " as part of the file format.
    Example 2:
    <?xml version="1.0" encoding="UTF-8"?>                
    <FDXLMDProdRcpt>                                      
        <FXNHdrLp>                                        
            <CrtDtTm>20070612151817</CrtDtTm>             
            <SessID>26796</SessID>                        
            <MsgTyp>861</MsgTyp>                          
            <MsgSubTyp>WRE_A</MsgSubTyp>                  
            <PrcsingPrty>5</PrcsingPrty>                  
            <SndTPQualCD>ZZ</SndTPQualCD>                 
            <SndTP>FSCS</SndTP>                           
            <RcvTPQualCD>ZZ</RcvTPQualCD>                 
            <RcvTP>EIB</RcvTP>                            
            <SndSrc>YANTRA</SndSrc>                       
            <RcvSrc>EIB</RcvSrc>                          
            <UsrID>VAR</UsrID>                            
        </FXNHdrLp>                                       
        <ProdRcptHdrLp>                                   
            <ShpID>VAR20070612NCHIC1</ShpID>              
            <ShpTyp> </ShpTyp>                            
            <ShpActnCD>00</ShpActnCD>                     
            <InTransMrgTyp> </InTransMrgTyp>              
            <ShpVolUOM>CI</ShpVolUOM>                     
            <ShpWgtUOM>LB</ShpWgtUOM>                     
            <ShpTotVol>310022.00</ShpTotVol>              
            <ShpTotWgt>861.00</ShpTotWgt>                 
            <DtTmLp>                                      
                <DtTyp>050</DtTyp>                        
                <DtTmQual>501</DtTmQual>                  
                <DtTm>2007-06-12T15:07:41-04:00</DtTm>    
            </DtTmLp>                                     
            <AdrLp>                                       
                <EntTyp>RC</EntTyp>                       
                <EntIDQual>93</EntIDQual>                 
                <EntID>NCHIC</EntID>                      
                <EntNm>NCHIC</EntNm>                      
                <AutoCrtTrdPar>0</AutoCrtTrdPar>          
                <AutoCrtTrdParRole>0</AutoCrtTrdParRole>  
                <AutoUpdtTrdPar>0</AutoUpdtTrdPar>        
            </AdrLp>                                      
            <ProdRcptTptLp>                               
                <TptIDQual>BOL</TptIDQual>                
                <TptSCAC> </TptSCAC>                      
                <TptID> </TptID>   
    Thanks and Best Regards
    Sitaraman

    You could try to use the following coding:
    *& Report  ZUS_SDN_UC_XML_TO_UTF8_TRANSF
    REPORT  zus_sdn_uc_xml_to_utf8_transf.
    define local data
    CONSTANTS:
      gc_encoding           TYPE string VALUE 'UTF-8'.
    DATA:
      gd_result             type string,
      go_ixml               TYPE REF TO if_ixml,
      go_stream_factory     TYPE REF TO if_ixml_stream_factory,
      go_encoding           TYPE REF TO if_ixml_encoding,
      go_resstream          TYPE REF TO if_ixml_ostream.
    DATA:
      gt_knb1    TYPE STANDARD TABLE OF knb1,
    gd_xml     TYPE string,
      gt_xml     TYPE TABLE OF string.
    START-OF-SELECTION.
      SELECT * FROM knb1 INTO TABLE gt_knb1 UP TO 10 ROWS
          WHERE bukrs = '1000'.
      go_ixml = cl_ixml=>create( ).
      go_stream_factory = go_ixml->create_stream_factory( ).
      go_encoding = go_ixml->create_encoding( character_set = gc_encoding
                                            byte_order = 0 ).
      go_resstream =
                  go_stream_factory->create_ostream_cstring( gd_result ).
      CALL METHOD go_resstream->set_encoding
        EXPORTING
          encoding = go_encoding.
    XML Transformieren
      CALL TRANSFORMATION id_indent
        SOURCE     itab = gt_knb1
        RESULT XML go_resstream.
      APPEND gd_result TO gt_xml.
      CALL METHOD cl_gui_frontend_services=>gui_download
        EXPORTING
         BIN_FILESIZE              =
          filename                  = 'C:\temp\xml_to_utf8.txt'
         FILETYPE                  = 'ASC'
         APPEND                    = SPACE
         WRITE_FIELD_SEPARATOR     = SPACE
         HEADER                    = '00'
         TRUNC_TRAILING_BLANKS     = SPACE
         WRITE_LF                  = 'X'
         COL_SELECT                = SPACE
         COL_SELECT_MASK           = SPACE
         DAT_MODE                  = SPACE
         CONFIRM_OVERWRITE         = SPACE
         NO_AUTH_CHECK             = SPACE
         CODEPAGE                  = SPACE
         IGNORE_CERR               = ABAP_TRUE
         REPLACEMENT               = '#'
         WRITE_BOM                 = SPACE
         TRUNC_TRAILING_BLANKS_EOL = 'X'
       IMPORTING
         FILELENGTH                =
        CHANGING
          data_tab                  = gt_xml
        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
          not_supported_by_gui      = 22
          error_no_gui              = 23
          OTHERS                    = 24.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    END-OF-SELECTION.
    However, I like to mention that the file created from out ECC 5.0 (6.40, non-Unicode) contains a special character between the XML header and the data part (when displayed using NotePad Editor):
    ...xml version="1.0" encoding="utf-8"?>[special character]<asx:abap xmlns:asx="http://www.sap.com/a...
    Using a HexEditor the special character (0x0A) is displayed as a dot.
    Also Check with FM - TREX_TEXT_TO_UTF8
    Reward Points if it is helpful
    Thanks
    Seshu

  • XML file is not being displayed in browser? Why?

    Hi all!
    I have a secnario file->XI->J2EE appl.
    I am using  File sender adapter and HTTP Receiver adapter.
    I placed XML file in D:\somedir of my machine, it is picking up well by XI, <b>all i want to know is how XI sends this XML file to my J2EE Appl.</b>Because my servlet should display the same XML file in browser. I deployed my J2EE appl on weblogic application server9.0 I am getting the following error:
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    XML document must have a top level element. Error processing resource 'http://localhost:7001/Invoke/DisplayRes'.
    These are settings that i have given in my Receiver HTTP adapter:
    Aadapter Type: HTTP
                       Receiver
    Transport Protocol:  HTTP1.0
    Message Protocol:    XI payload in HTTP body
    Adapter Engine:      Integration Server
    Addressing Type:     URL address
    Target host:         localhost
    Service Number:      7001(Port number of Weblogic appl server--where my J2EE appl is deployed).
    Path     :  /Invoke/DisplayRes/(Context path of J2EE appl)
    Authentication Type:Use Logon Data for SAP System
    Content Type: text/xml
    Username:   xiappluser
    password:   xx
    XML code:   UTF-8
    This is my Servlet code:
    public class DisplayRes extends HttpServlet {
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         doPost(request,response);
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         BufferedReader brin =new BufferedReader(new InputStreamReader(request.getInputStream()));
         String inputLine;
         StringBuffer sBuf = new StringBuffer();
         PrintWriter out = response.getWriter();
         response.setContentType("text/xml");
         while ((inputLine = brin.readLine()) != null)
             sBuf.append(inputLine);
               out.println(sBuf.toString());
              brin.close();
             out.flush();
    Where i went wrong please help me,
    NOTE: I want to know how XI sends XML file to my J2EE appl. I suppose my servlet receives it in request object.If so can i use like:
    response.setContentType("text/xml");
      String xmlFile = request.getParameter("myXMLFile");
      PrintWriter out = response.getWriter();
      out.write(xmlFile);
      out.flush();
      out.close();
    Please help me!
    Thanks a lot!

    Hi Datta,
    You seem to have big problem with this scneario as you have raised this question couple of times , in couple of topics / threads. I will try to make a few things about this clear.
    1. XI when sends data to a J2EE application , in your case a servlet, I believe you must be using a HTTP adapter to post the data to it. Whenever XI will post a XML data to a HTTP resource , it will post it as the request body and that is why the code in one of my previous post reads,
    BufferedReader brin =new BufferedReader(new InputStreamReader(request.getInputStream()));
    String inputLine;
    StringBuffer sBuf = new StringBuffer();
    PrintWriter out = response.getWriter();
    response.setContentType("text/xml");
    while ((inputLine = brin.readLine()) != null)
    sBuf.append(inputLine);
    out.println(sBuf.toString());
    brin.close();
    out.flush();
    If you 've noticed, the statement
    request.getInputStream()
    retrieves the body of the request as binary data using a ServletInputStream.
    So your answer to your question is
    <b>XI transferes data to a servlet as a part of HTTP request body</b>, if you use a HTTP adapter.
    2. By J2EE application , if you mean a server java proxy, then the method whose name matches with that of the Inbound Message interface recieves a parameter , from which you can retrieve the parameters passed by XI. Just check the getters of that object.
    Hope this clears your basic doubts!!!
    Rgds,
    Amol

  • Adding data in an XML file

    how to add  data in xml file from textbox in c# without overwriting???

    Hi,
    As Andy said,  add data to an xml file is overwriting, if you mean append data to xml file, please look this article:
    http://codesamplez.com/programming/linq-to-xml-tutorial, Since this issue is more related to ASP.net, you could also ask this issue in asp.net forum:
    http://forums.asp.net/
    Best Regards,
    Jambor
    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.

  • XML file not generating Completely

    Hi ,
    I am reading a file from the Application Server of XML format in Binary Mode. After reading I am checking the contents and with every 255 Char I am appending the contents in the different row, thus creating a internal table having one field of length 255.
    I am using this table to send an email to the recepient using the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'. This is generating a Attachment. But when I open this in Internet browser, It is not getting compete contents.
    I am not sure, If I have missed something.
    Regards,
    Arpit

    Hi Chen,
    Thanks for thr reply. The XML file contains data related to Idocs.The complete result If I open a XML file is
    <?xml version="1.0" encoding="UTF-8" ?>
    - <DELVRY03>
    - <IDOC BEGIN="1">
    - <EDI_DC40 SEGMENT="1">
      <TABNAM>EDI_DC40</TABNAM>
      <MANDT>002</MANDT>
      <DOCNUM>0000000000071931</DOCNUM>
      <DOCREL>620</DOCREL>
      <STATUS>30</STATUS>
      <DIRECT>1</DIRECT>
      <OUTMOD>2</OUTMOD>
      <IDOCTYP>DELVRY03</IDOCTYP>
      <MESTYP>SHPORD</MESTYP>
      <STDMES>SHPORD</STDMES>
      <SNDPOR>SAPAD1</SNDPOR>
      <SNDPRT>LS</SNDPRT>
      <SNDPRN>AD1002LS</SNDPRN>
      <RCVPOR>XML_PORT</RCVPOR>
      <RCVPRT>LS</RCVPRT>
      <RCVPFC>LS</RCVPFC>
      <RCVPRN>HT</RCVPRN>
      <CREDAT>20110405</CREDAT>
      <CRETIM>070247</CRETIM>
      <SERIAL>20110218054703</SERIAL>
      </EDI_DC40>
    - <E1EDL20 SEGMENT="1">
      <VBELN>0080004041</VBELN>
      <VSTEL>GB03</VSTEL>
      <VKORG>170</VKORG>
      <INCO1>DDU</INCO1>
      <ROUTE>DGGBPA</ROUTE>
      <VSBED>E1</VSBED>
      <BTGEW>315.000</BTGEW>
      <NTGEW>315.000</NTGEW>
      <GEWEI>KGM</GEWEI>
      <VOLUM>0.000</VOLUM>
      <ANZPK>00000</ANZPK>
      <PODAT>20110218</PODAT>
      <POTIM>161703</POTIM>
    - <E1EDL22 SEGMENT="1">
      <VSTEL_BEZ>FSQ HT West Drayton</VSTEL_BEZ>
      <VKORG_BEZ>FSQ</VKORG_BEZ>
      <INCO1_BEZ>Delivered Duty Unpaid</INCO1_BEZ>
      <VSBED_BEZ>UK Standard</VSBED_BEZ>
      </E1EDL22>
    - <E1EDL21 SEGMENT="1">
      <LFART>ZCOR</LFART>
      <LPRIO>02</LPRIO>
      <TRAGR>Z001</TRAGR>
    - <E1EDL23 SEGMENT="1">
      <LFART_BEZ>Correction Delivery</LFART_BEZ>
      <LPRIO_BEZ>Standard</LPRIO_BEZ>
      <TRAGR_BEZ>Standard</TRAGR_BEZ>
      </E1EDL23>
      </E1EDL21>
    - <E1EDL18 SEGMENT="1">
      <QUALF>ORI</QUALF>
      </E1EDL18>
    - <E1ADRM1 SEGMENT="1">
      <PARTNER_Q>AG</PARTNER_Q>
      <PARTNER_ID>0060004842</PARTNER_ID>
      <LANGUAGE>EN</LANGUAGE>
      <FORMOFADDR>Mr.</FORMOFADDR>
      <NAME1>Sabu P Kuriakose</NAME1>
      <NAME2>KURIA</NAME2>
      <STREET1>Flat 2 St.Raphael's House. Sherborne Roa</STREET1>
      <POSTL_COD1>RG215TG</POSTL_COD1>
      <CITY1>Basingstoke</CITY1>
      <TELEPHONE1>01256351078</TELEPHONE1>
      <COUNTRY1>GB</COUNTRY1>
      <REGION>HA</REGION>
      </E1ADRM1>
    - <E1ADRM1 SEGMENT="1">
      <PARTNER_Q>WE</PARTNER_Q>
      <PARTNER_ID>0060004842</PARTNER_ID>
      <LANGUAGE>EN</LANGUAGE>
      <FORMOFADDR>Mr.</FORMOFADDR>
      <NAME1>Sabu P Kuriakose</NAME1>
      <NAME2>KURIA</NAME2>
      <STREET1>Flat 2 St.Raphael's House. Sherborne Roa</STREET1>
      <POSTL_COD1>RG215TG</POSTL_COD1>
      <CITY1>Basingstoke</CITY1>
      <TELEPHONE1>01256351078</TELEPHONE1>
      <COUNTRY1>GB</COUNTRY1>
      <REGION>HA</REGION>
      </E1ADRM1>
    - <E1ADRM1 SEGMENT="1">
      <PARTNER_Q>OSP</PARTNER_Q>
      <PARTNER_ID>GB03</PARTNER_ID>
      <LANGUAGE>EN</LANGUAGE>
      <NAME1>Four Square UK</NAME1>
      <STREET1>Armstrong Road</STREET1>
      <POSTL_COD1>RG24 8NU</POSTL_COD1>
      <CITY1>Basingstoke</CITY1>
      <COUNTRY1>GB</COUNTRY1>
      <REGION>HA</REGION>
      </E1ADRM1>
    - <E1ADRM1 SEGMENT="1">
      <PARTNER_Q>OSO</PARTNER_Q>
      <PARTNER_ID>170</PARTNER_ID>
      <LANGUAGE>EN</LANGUAGE>
      <NAME1>Four Square UK</NAME1>
      <STREET1>Armstrong Road</STREET1>
      <POSTL_COD1>RG24 8NU</POSTL_COD1>
      <CITY1>Basingstoke</CITY1>
      <COUNTRY1>GB</COUNTRY1>
      <REGION>HA</REGION>
      </E1ADRM1>
    - <E1EDT13 SEGMENT="1">
      <QUALF>006</QUALF>
      <NTANF>20100420</NTANF>
      <NTANZ>000000</NTANZ>
      <NTEND>20100420</NTEND>
      <NTENZ>000000</NTENZ>
      <ISDD>20100419</ISDD>
      <ISDZ>000000</ISDZ>
      <IEDD>20100419</IEDD>
      <IEDZ>000000</IEDZ>
      </E1EDT13>
    - <E1EDT13 SEGMENT="1">
      <QUALF>003</QUALF>
      <NTANF>20100420</NTANF>
      <NTANZ>000000</NTANZ>
      <NTEND>20100420</NTEND>
      <NTENZ>000000</NTENZ>
      <ISDD>00000000</ISDD>
      <ISDZ>000000</ISDZ>
      <IEDD>00000000</IEDD>
      <IEDZ>000000</IEDZ>
      </E1EDT13>
    - <E1EDT13 SEGMENT="1">
      <QUALF>001</QUALF>
      <NTANF>20100420</NTANF>
      <NTANZ>000000</NTANZ>
      <NTEND>20100420</NTEND>
      <NTENZ>000000</NTENZ>
      <ISDD>00000000</ISDD>
      <ISDZ>000000</ISDZ>
    The XML page cannot be displayed
    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
    Invalid at the top level of the document. Error processing resource 'file:///C:/TEMP/notesEC3FD6/~4120145.xml'.
    Regards,
    Arpit

Maybe you are looking for