ABAP to XML File (Simple Transformation)
Hi guys,
this is my first question here and if I do something wrong please tell me about it.
I created my own simple transformation which I use in my program:
CALL TRANSFORMATION ZST_MAGAZYN_BB
SOURCE lt_magazyn_rh = lt_magazyn_rh[]
lt_mag_hdr = lt_mag_hdr[]
lt_mag_hdr2 = lt_mag_hdr2[]
RESULT XML xml_string.
Then I tried to use GUI_DOWNLOAD on "xml_string" but there is no content in output xml file (but file's size is not 0kb):
DATA: xml_table TYPE STANDARD TABLE OF string.
APPEND xml_string TO xml_table.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'C:\rh.xml'
TABLES
data_tab = xml_table.
I would really appreciate your help.
Try to change the path where you're saving the file.
I had the same problem once, it was authorization. I couldn't save in C:\ root.
Change filename = 'C:\rh.xml' to filename = 'C:\TEMP\rh.xml'.
Or try any other path, but C:\
Similar Messages
-
How to update the value in xml file using transformer after setNodeValue
Hi,
This is my code
I want to set update the values in xml file using transformer..
Any one can help me
This is my Xml file
<?xml version="1.0" encoding="UTF-8"?>
<place>
<name>chennai</name>
</place>
Jsp Page
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="javax.xml.parsers.DocumentBuilderFactory,
javax.xml.parsers.DocumentBuilder,org.w3c.dom.*,org.w3c.dom.Element"
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<% String str="";
String str1="";
try
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse("http://localhost:8084/XmlApplication1/sss.xml");
out.println("Before change");
NodeList n11 = doc.getElementsByTagName("name");
Node n22= n11.item(0).getFirstChild();
str1 = n22.getNodeValue();
out.println(str1);
out.println("After change");
String name = "Banglore";
NodeList nlst = doc.getElementsByTagName("name");
Node node= nlst.item(0).getFirstChild();
node.setNodeValue(name);
NodeList n1 = doc.getElementsByTagName("name");
Node n2= n1.item(0).getFirstChild();
str = n2.getNodeValue();
out.println(str);
catch(Exception e)
out.println(e) ;
%>
<h1><%=str%></h1>
<%--
This example uses JSTL, uncomment the taglib directive above.
To test, display the page like this: index.jsp?sayHello=true&name=Murphy
--%>
<%--
<c:if test="${param.sayHello}">
<!-- Let's welcome the user ${param.name} -->
Hello ${param.name}!
</c:if>
--%>
</body>
</html>hi check this exit...
IWO10012 -
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
SitaramanYou 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 -
Successful Read of XML File by Transforms Return Null
Hi:
I'm starting out with a simple BPEL process: Read an XML file, transform two fields. write an XML file. Both the read and write operations use the same .xsd file.
I am successful at creating, compiling, deploying, and executing the process. The output file contains empty tags. In the BPEL Console and can see each activity. The read activity shows the data read from the input file, arranged as expected. The I conclude that this activity works correctly. Here is what I see when I drill down on the first activity:
<?xml version="1.0" encoding="UTF-8" ?>
- <user-details>
- <user-list>
- <user>
<first-name>test1</first-name>
<last-name>abc</last-name>
<gender>male</gender>
<age>1</age>
</user>
</user-list>
</user-details>
The second activity shows empty values for the tags defined for the target variable. Here's what I see for the second activity, the Transform activity:
<Invoke_WriteOut_Variable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="user-details"><user-details xmlns:ns0="http://www.example-irfan.org" xmlns="http://www.example-irfan.org">
<ns0:user>
<ns0:firstName/>
<ns0:lastName/>
<ns0:gender/>
<ns0:age/>
</ns0:user>
</user-details>
</part></Invoke_WriteOut_Variable>
This second activity, the Transform, simply maps fields received from activity one too a new variable defined using the same .xsd as the first variable.
The third activity writes to the output file. Here is that file:
<?xml version="1.0" ?><user-details xmlns:ns0="http://www.example-irfan.org" xmlns="http://www.example-irfan.org">
<ns0:user>
<ns0:firstName/>
<ns0:lastName/>
<ns0:gender/>
<ns0:age/>
</ns0:user>
</user-details>
This is a "simple" 3-activity process, and I've reviewed it thoroughly. Can anyone help? It seems that the variable defined to accept the input xml file is not getting populated, although the process manager seems to say differently. Why would this be?
Thanks.Thank you for your response. My problem and confusion indeed relate to the xsd file. I know this because I can take one of the sample processes and modify it to perform the simple task that I want: open an xml file, transform a field or two, write to a new xml file. Still I have not been able to understand what BPEL considers a "valid" xsd file. I have tried like heck to match my xsd file to match the sample, but it still doesn't work.
So, my next question to anyone: does any documentation exist on the proper format for an xsd file? I have tried to take examples from on-line postings and blogs, but these don't work. It seems to me that the initial <schema> tag is the most important and that the http references in this tag are vital, but I can't tell for sure.
Any suggestions are appreciated. -
Load XML file and transform to table in database
Hi All,
If I have a xml file as sample xml data
<EMPLOYEES>
- <EMP>
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>17-DEC-80</HIREDATE>
<SAL>800</SAL>
</EMP>
</EMPLOYEES>
And I need to import to Emplyees table
Create table Employees
( EMPNO number,
ENAME varchar2(100),
JOB varchar2(100),
MGR number,
HIREDATE date,
SAL number
How to import the xml file to the table?
Regards,
HikoWell, if it's a complex XML you can use register a Schema and shred the XML to tables as described on the following thread:
Re: XML file processing into oracle
Or if it's fairly simple XML, you can just use XMLTABLE to flatten the data out...
SQL> ed
Wrote file afiedt.buf
1 WITH xml_table AS
2 (SELECT xmltype('
3 <root>
4 <child name="name1">
5 <grandchild name="name11">
6 <greatgrandchild name="name111"/>
7 <greatgrandchild name="name112"/>
8 </grandchild>
9 <grandchild name="name12"/>
10 </child>
11 <child name="name2">
12 <grandchild name="name21"/>
13 <greatgrandchild name="name211"/>
14 <grandchild name="name22"/>
15 </child>
16 </root>') object_value FROM dual)
17 select po.child_name, gc.gchild_name, ggc.ggchild_name
18 from xml_table p
19 ,xmltable('/root/child'
20 passing p.object_value
21 columns child_name varchar2(100) path '@name'
22 ,gchild xmltype path 'grandchild'
23 ) po
24 ,xmltable('/grandchild'
25 passing po.gchild
26 columns gchild_name varchar2(100) path '@name'
27 ,ggchild xmltype path 'greatgrandchild'
28 ) (+) gc
29 ,xmltable('/greatgrandchild'
30 passing gc.ggchild
31 columns ggchild_name varchar2(100) path '@name'
32* ) (+) ggc
SQL> /
CHILD_NAME GCHILD_NAME GGCHILD_NAME
name1 name11 name111
name1 name11 name112
name1 name12
name2 name21
name2 name22and then insert the results into whatever table(s) you want. -
XML escaping issue in ABAP during XML file transfer to App. Server.
Hello Partners:
I was going through some work of XML integration of SAP with a third-party. But came across an issue:
The text descriptions we are sending within an XML tag has certain special characters like '&'. But the XML parser is not escaping it. Hence its replacing '&' with "&" in the XML data string. So now I need to understand how can we implement escaping via ABAP for generated XML strings? Can you all please help me to understand which methods to use and how?
It will be much appreciated.
Thanks in advance.
Vivek Singh.Hello SAP Friends!
I'm facing the same problem concerning special chars in XML. I've tried to unescape the '&' sign with methods of if_ixml_ostream
l_ostream->set_ignore_escaping( ignore_escaping = '&' ).
the character is set and can be called by
l_str = l_ostream->get_ignore_escaping( ).
After the rendering was done and the download has finished the xml document can be loaded in EXCEL but the special characters are replaced by & a m p;
Has anybody found a method to avoid the behaviour?
My original problem is, the the data have to be in one cell in excel. I know at present no method to download data (text including line feeds) from SAP to excel into one cell.
Maybe you have found a way to use ignore_escaping in correct way!
Thanks a lot in advance!!! -
Create xml tag dynamically within simple transformation
Hi all together,
I'm faceing the following problem:
There is a internal table provided, consisting of name/value-pairs. Something like
ls_struc-name = 'NAME1'.
ls_struc-value = 'XYZ'.
append ls_struc to lt_struc
ls_struc-name = 'CITY1'.
ls_struc-value = 'Munich'.
append ls_struc to lt_struc
and so on.
I have to create this XML (with simple transformation):
<NAME1>XYZ</NAME1>
<CITY1>Munich</CITY1>
Everythings works fine so far (tables, values etc.), but I have problems with creating the XML-Tag, e.g <NAME1> from "$line.name" within the transformation. I don't have any information about the data structure (therefore "call transaction id" does not work).
Any hint is useful!!!
Best regards,
ThomasExaple program for creating XML file from abap
REPORT z_xit_xml_dom_create.
TYPE-POOLS: ixml.
TYPES: BEGIN OF xml_line,
data(256) TYPE x,
END OF xml_line.
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_ostream TYPE REF TO if_ixml_ostream,
l_renderer TYPE REF TO if_ixml_renderer,
l_document TYPE REF TO if_ixml_document.
DATA: l_element_flights TYPE REF TO if_ixml_element,
l_element_airline TYPE REF TO if_ixml_element,
l_element_flight TYPE REF TO if_ixml_element,
l_element_from TYPE REF TO if_ixml_element,
l_element_to TYPE REF TO if_ixml_element,
l_element_dummy TYPE REF TO if_ixml_element,
l_value TYPE string.
DATA: l_xml_table TYPE TABLE OF xml_line,
l_xml_size TYPE i,
l_rc TYPE i.
DATA: lt_spfli TYPE TABLE OF spfli.
DATA: l_spfli TYPE spfli.
START-OF-SELECTION.
* Fill the internal table
SELECT * FROM spfli INTO TABLE lt_spfli.
* Sort internal table
SORT lt_spfli BY carrid.
* Start filling xml dom object from internal table
LOOP AT lt_spfli INTO l_spfli.
AT FIRST.
* Creating a ixml factory
l_ixml = cl_ixml=>create( ).
* Creating the dom object model
l_document = l_ixml->create_document( ).
* Fill root node with value flights
l_element_flights = l_document->create_simple_element(
name = 'flights'
parent = l_document ).
ENDAT.
AT NEW carrid.
* Create element 'airline' as child of 'flights'
l_element_airline = l_document->create_simple_element(
name = 'airline'
parent = l_element_flights ).
* Create attribute 'code' of node 'airline'
l_value = l_spfli-carrid.
l_rc = l_element_airline->set_attribute( name = 'code' value = l_value ).
* Create attribute 'name' of node 'airline'
SELECT SINGLE carrname FROM scarr INTO l_value WHERE carrid EQ l_spfli-carrid.
l_rc = l_element_airline->set_attribute( name = 'name' value = l_value ).
ENDAT.
AT NEW connid.
* Create element 'flight' as child of 'airline'
l_element_flight = l_document->create_simple_element(
name = 'flight'
parent = l_element_airline ).
* Create attribute 'number' of node 'flight'
l_value = l_spfli-connid.
l_rc = l_element_flight->set_attribute( name = 'number' value = l_value ).
ENDAT.
* Create element 'from' as child of 'flight'
CONCATENATE l_spfli-cityfrom ',' l_spfli-countryfr INTO l_value.
l_element_from = l_document->create_simple_element(
name = 'from'
value = l_value
parent = l_element_flight ).
* Create attribute 'airport' of node 'from'
l_value = l_spfli-airpfrom.
l_rc = l_element_from->set_attribute( name = 'airport' value = l_value ).
* Create element 'to' as child of 'flight'
CONCATENATE l_spfli-cityto ',' l_spfli-countryto INTO l_value.
l_element_to = l_document->create_simple_element(
name = 'to'
value = l_value
parent = l_element_flight ).
* Create attribute 'airport' of node 'from'
l_value = l_spfli-airpto.
l_rc = l_element_to->set_attribute( name = 'airport' value = l_value ).
* Create element 'departure' as child of 'flight'
l_value = l_spfli-deptime.
l_element_dummy = l_document->create_simple_element(
name = 'departure'
value = l_value
parent = l_element_flight ).
* Create element 'arrival' as child of 'flight'
l_value = l_spfli-arrtime.
l_element_dummy = l_document->create_simple_element(
name = 'arrival'
value = l_value
parent = l_element_flight ).
* Create element 'type' as child of 'flight'
CASE l_spfli-fltype.
WHEN 'X'.
l_value = 'Charter'.
WHEN OTHERS.
l_value = 'Scheduled'.
ENDCASE.
l_element_dummy = l_document->create_simple_element(
name = 'type'
value = l_value
parent = l_element_flight ).
ENDLOOP.
IF sy-subrc NE 0.
MESSAGE 'No data into db table ''spfli'', please run program ''SAPBC_DATA_GENERATOR'' with transaction ''SA38''' TYPE 'E'.
ENDIF.
* Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
* Connect internal XML table to stream factory
l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ).
* Rendering the document
l_renderer = l_ixml->create_renderer( ostream = l_ostream
document = l_document ).
l_rc = l_renderer->render( ).
* Saving the XML document
l_xml_size = l_ostream->get_num_written_raw( ).
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = l_xml_size
filename = 'c:\temp\flights.xml'
filetype = 'BIN'
CHANGING
data_tab = l_xml_table
EXCEPTIONS
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. -
How to add attribute to the elements in XML file in BPEL transformation
Hi All-
I have to create a XML file using transformation and file adapater and the parent element is USERRECORDS, now when I am creating the XML file using transformation the XML get creates like
<?xml version="1.0">
<USERRECORDS>
so on
But I want the parent element and the xml version tags as:
<?xml version="1.0" encoding="UTF-8"?>
<USERRECORDS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mySchema.xsd">
as I need to add the attributes.
Is it possible in transformation?
Any idea, please suggest.
Thanks and Regards,
SreejitI have never come across any functionality like that.
However I assigned values to attributes in Assign Acitivity using XML Fragment on source side. -
Group columns in Excel using XSLT simple transformation
Hi All,
I have to group a few columns in the excel so that they can be expanded or collapsed. I am transforming an internal table into XML using Simple transformation. In this XSLT, I need to add the code to group the particular columns together in the final excel.
Can any one please help me in acheiving the columns grouped together.
Thanks and Regards,
Vishnu.
Edited by: Vishnu Kare on Mar 24, 2011 7:22 AMHi Vishnu, I am also using simple transformations (not XSLT) to create XML excel from SAP data. I always create a template excel workbook from excel by saving it as XML file. This XML can be pasted into the SAP transformation without completely understanding the Microsoft excel syntax. The dynamic SAP data then can be included to the XML in the transformation.
Regards Jack -
Combine several XML files with same structure
Hello,
I have several XML files with the same structure and I want to combine them and create a new XML file to be bale to compare that information easily. It does not look very difficult but as I am very new in this I am not bale to get it
The structure of my actual files would be something simlar to:
Root->...-> Name->Address, Telephone
And what I would like to have si something like
Root->.... ->Address-> Name 1,Name 2....
Root -> ...->Telephone-> Name 1, Name 2....
Does anyone know how to do this.
ThanksYou could write a XSL transformation file that does this and transform your input file via
* Transform XML file with a style sheet.
* <p><b>Example:</b><p>
<table align="center" bgcolor="#E0E0E0" border=1 cellpadding="10" cellspacing="0"><tr><td><pre style="margin-top:0; margin-bottom:0">
XMLTransformer t = new XMLTransformer();
FileOutputStream fos = new FileOutputStream("C:/Project/result.html");
String xmlFile = "C:/Project/source.xml";
String styleSheet = "C:/Project/stylesheet.xsl";
t.transform(xmlFile, styleSheet, fos);
</pre></td></tr></table>
* @param xmlfile The XML file to transform.
* @param style Stylesheet to use for transformation.
* @param outputStream OutputStream to write the transformed result to.
public void transform(String xmlfile, String style, OutputStream outputStream) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//factory.setNamespaceAware(true);
//factory.setValidating(true);
//todo: use inputstreams instead of file names
try {
File stylesheet = new File(style);
File datafile = new File(xmlfile);
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(datafile);
// Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = tFactory.newTransformer(stylesource);
DOMSource source = new DOMSource(document);
StreamResult sr = new StreamResult(outputStream);
transformer.transform(source, sr);
} catch (TransformerConfigurationException tce) {
// Error generated by the parser
System.out.println ("\n**XMLTransformerr Factory error");
System.out.println(" " + tce.getMessage() );
// Use the contained exception, if any
Throwable x = tce;
if (tce.getException() != null) {
x = tce.getException();
x.printStackTrace();
} catch (TransformerException te) {
// Error generated by the parser
System.out.println ("\n** Transformation error");
System.out.println(" " + te.getMessage() );
// Use the contained exception, if any
Throwable x = te;
if (te.getException() != null) {
x = te.getException();
x.printStackTrace();
} catch (SAXException sxe) {
// Error generated by this application
// (or a parser-initialization error)
Exception x = sxe;
if (sxe.getException() != null) {
x = sxe.getException();
x.printStackTrace();
} catch (ParserConfigurationException pce) {
// Parser with specified options can't be built
pce.printStackTrace();
} catch (IOException ioe) {
// I/O error
ioe.printStackTrace();
}//transform() -
How to convert xml file to xsl using java
Hi all,
I have an XML file with which i need to convert(transform) it to an xsl file using java.
I am new to converting xml file to xslt.Please send me if u have code .
Thanks in advance
regards
RamYou seem to be asking the wrong question. An XSL file can be used to transform an XML file, but transforming an XML into an XSL does not make sense. The API for running XSL transforms on the Java platform is described here:
http://java.sun.com/javase/6/docs/api/javax/xml/transform/package-summary.html -
Write XML file in application server
Experts,
I'm using a transformation to generate a xml file:
CALL TRANSFORMATION zdatafechomes
SOURCE ficheiroexecucao = gt_source[]
RESULT XML xml_result.
It's working fine. But i'm having problems in putting the "xml_result" (it's a type xtring) into the application server.
Anyone knows how to do it ? Transaction cg3z it's different because the file comes from C:
Best Regards,
Mário.Hello Mario
I do not see why the following logic should not work:
*& Report ZUS_SDN_XML_XSTRING_APPLSERVER
REPORT ZUS_SDN_XML_XSTRING_APPLSERVER.
DATA:
gd_dsn type string,
gd_xstring type xstring,
gt_kna1 type STANDARD TABLE OF kna1.
start-of-selection.
select * from kna1 into table gt_kna1 up to 10 rows.
BREAK-POINT.
call TRANSFORMATION id
source itab = gt_kna1
result xml = gd_xstring.
gd_dsn = '/tmp/xml_as_xstring.file'.
open DATASET gd_dsn for OUTPUT in BINARY MODE.
check ( syst-subrc = 0 ).
TRANSFER gd_xstring to gd_dsn.
CLOSE DATASET gd_dsn.
end-of-SELECTION.
Regards
Uwe -
DefaultMutableTreeNode to XML file
Morning all, i have a program that writes a node to an xml file.
it looks like so:
public void write(DefaultMutableTreeNode root) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
//now to create the document object that will house the tree.
Document doc = builder.newDocument();
Element documentRoot = (Element) root;
//Add the root element to the document tree.
doc.appendChild(documentRoot);
//Output the DOM tree.
//Create the necessary transformers.
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
//transform the DOM tree to output XML file.
transformer.transform(new DOMSource(doc), new StreamResult(new FileOutputStream("testfile.xml")));
}catch(Exception e) {
e.printStackTrace();
}im trying to cast my defaultmutabletreenode to an element or some sort of argument that the Document constructor can take.i want to write the hierarchy i have in the DefaultMutableTreeNode to an xml file. Note that this node is a root node.I cant seem to find a solution in the api's, has anyone any ideas?
Many thanksits ok, i found out it cant be done.a bold statetment! ;)
there are various ways using TreePath to get the hierarchy of a given node. the node, as you found out, does not contain the hierarchy. but if you are talking about the root node, your statement probably is right (what hieracht should have in the first place ;).
thomas -
HI All,
my requirement is to put the generated XML file (via transformation) on clients FTP ,anybody have idea how to achieve this.
Thanks ,
RuchiHello
You can check [here |http://help.sap.com/saphelp_nw70/helpdata/EN/0d/00453c91f37151e10000000a11402f/frameset.htm]the information on how to setup the FTP and send the XML file.
Regards
Joaquin -
Simple Transformation to deserialize an XML file into ABAP data structures?
I'm attempting to write my first simple transformation to deserialize
an XML file into ABAP data structures and I have a few questions.
My simple transformation contains code like the following
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates"
xmlns:pp="http://www.sap.com/abapxml/types/defined" >
<tt:type name="REPORT" line-type="?">
<tt:node name="COMPANY_ID" type="C" length="10" />
<tt:node name="JOB_ID" type="C" length="20" />
<tt:node name="TYPE_CSV" type="C" length="1" />
<tt:node name="TYPE_XLS" type="C" length="1" />
<tt:node name="TYPE_PDF" type="C" length="1" />
<tt:node name="IS_NEW" type="C" length="1" />
</tt:type>
<tt:root name="ROOT2" type="pp:REPORT" />
<QueryResponse>
<tt:loop ref="ROOT2" name="line">
<QueryResponseRow>
<CompanyID>
<tt:value ref="$line.COMPANY_ID" />
</CompanyID>
<JobID>
<tt:value ref="$line.JOB_ID" />
</JobID>
<ExportTypes>
<tt:loop>
<ExportType>
I don't know what to do here (see item 3, below)
</ExportType>
</tt:loop>
</ExportTypes>
<IsNew>
<tt:value ref="$line.IS_NEW"
map="val(' ') = xml('false'), val('X') = xml('true')" />
</IsNew>
</QueryResponseRow>
</tt:loop>
</QueryResponse>
</tt:loop>
1. In a DTD, an element can be designated as occurring zero or one
time, zero or more times, or one or more times. How do I write the
simple transformation to accommodate these possibilities?
2. In trying to accommodate the "zero or more times" case, I am trying
to use the <tt:loop> instruction. It occurs several layers deep in the
XML hierarchy, but at the top level of the ABAP table. The internal
table has a structure defined in the ABAP program, not in the data
dictionary. In the simple transformation, I used <tt:type> and
<tt:node> to define the structure of the internal table and then
tried to use <tt:loop ref="ROOT2" name="line"> around the subtree that
can occur zero or more times. But every variation I try seems to get
different errors. Can anyone supply a working example of this?
3. Among the fields in the internal table, I've defined three
one-character fields named TYPE_CSV, TYPE_XLS, and TYPE_PDF. In the
XML file, I expect zero to three elements of the form
<ExportType exporttype='csv' />
<ExportType exporttype='xls' />
<ExportType exporttype='pdf' />
I want to set field TYPE_CSV = 'X' if I find an ExportType element
with its exporttype attribute set to 'csv'. I want to set field
TYPE_XLS = 'X' if I find an ExportType element with its exporttype
attribute set to 'xls'. I want to set field TYPE_PDF = 'X' if I find
an ExportType element with its exporttype attribute set to 'pdf'. How
can I do that?
4. For an element that has a value like
<ErrorCode>123</ErrorCode>
in the simple transformation, the sequence
<ErrorCode> <tt:value ref="ROOT1.CODE" /> </ErrorCode>
seems to work just fine.
I have other situations where the XML reads
<IsNew value='true' />
I wanted to write
<IsNew>
<tt:value ref="$line.IS_NEW"
map="val(' ') = xml('false'), val('X') = xml('true')" />
</IsNew>
but I'm afraid that the <tt:value> fails to deal with the fact that in
the XML file the value is being passed as the value of an attribute
(named "value"), rather than the value of the element itself. How do
you handle this?Try this code below:
data l_xml_table2 type table of xml_line with header line.
W_filename - This is a Path.
if w_filename(02) = '
open dataset w_filename for output in binary mode.
if sy-subrc = 0.
l_xml_table2[] = l_xml_table[].
loop at l_xml_table2.
transfer l_xml_table2 to w_filename.
endloop.
endif.
close dataset w_filename.
else.
call method cl_gui_frontend_services=>gui_download
exporting
bin_filesize = l_xml_size
filename = w_filename
filetype = 'BIN'
changing
data_tab = l_xml_table
exceptions
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.
Maybe you are looking for
-
Error while activating the business content object
Hi guru, We have installed a new BI system, and hence we need to activate all the business content object as they are available in delivery version. So as there was an requirement i tryed to activate the business content object ,that is 0mat (MATNR)
-
My OSX Mountain LIon is still downloading after the download was initiated 12 hours ago. What's wrong?
-
When I attempt to download 7.2, I am taken immediately to the "Thanks for downloading" page even though no download has occurred. I'm using WinXP Media Edition w/ Service Pack 2, Firefox 2.x (I added itunes.com to trusted site list, allowed cookies,
-
What is the best DVD burner to buy for use with my Mac?
I have a MacMini with a DVD player/CD burner. I would like to buy an external DVD burner for use with the MacMini and my Tiger OS. Could I get some thoughts on purchasing a good external burner and using the best burning program with it. Thanks
-
Is the complete query overwritten once it is transported to another system?
Hi, I had developed a query with some variables on the infoset. This has been transported to the production system. But due to some requirement change the infoset was impacted due to the changes made in the ODS. (on which the infoset was created). So