Remove xml declarations when using xslt
Hi, i have created an xslt which transforms an xml file and then imports the information into a mysql database. It works and imports the information into the database but it also brings across the xml delcarations and the node names.
Is there a coldfusion way to remove these declarations, all i want is the information itself brought into the database.
Thanks
Chris
Hi Adam,
here is the code from the xsl file:
<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="data/itemfeed.xml" --><!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
<!ENTITY copy "©">
<!ENTITY reg "®">
<!ENTITY trade "™">
<!ENTITY mdash "—">
<!ENTITY ldquo "“">
<!ENTITY rdquo "”">
<!ENTITY pound "£">
<!ENTITY yen "¥">
<!ENTITY euro "€">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<xsl:for-each select="Items/Item[ItemType='Standard']">
<xsl:value-of select="EANNumber"/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
And here is some sample data from the XML file:
<?xml version="1.0" encoding="UTF-8" ?>
<Items>
<Item>
<ItemType>Standard</ItemType>
<EANNumber>111222333444</EANNumber>
</Item>
</Items>
Thanks alot, i appreciate the help.
Chris
Similar Messages
-
Omit the XML declaration when using the PHP MM_XSLTransform class
Hi
Is there any way to omit the XML declaration when using the
PHP MM_XSLTransform class?
When using the PHP MM_XSLTransform to transform some XML into
HTML, the XML declaration is faithfully delivered, which is
expected. In my case though this ends up in the body of the
document and is not desired. I wish to choose that the XML
declaration is not shown.
I have tried to use the <xsl:output method="xml"
encoding="utf-8" omit-xml-declaration="yes"/> in the XSL
stylesheet but the declaration still appears.
Any help?
all the best
DaveJim20005 wrote:
> I'm using XLS transfomation in DW for reading XML files.
Now (I'm just back
> form holiday), my webspace provider has updated to php
5.1.5. I'm getting this
> error:
Comment out line 301 and add two new lines immediately after
it like this:
// $xml = DOMDocument::loadXML($content);
$doc = new DOMDocument();
$err = $doc->loadXML($content);
This is part of a PHP 8.0.2 hotfix that can be obtained
directly from
Adobe support.
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/ -
Is it possible to remove xml declaration from a target HTTP msg in PI 7.1?
Hello,
I am working on a SOAP to HTTP scenario in PI 7.1.
I am using a java mapping to create a target string. This target string does not contain XML declaration(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>) in it.
To elaborate the issue, while testing the message mapping, this XML declaration is not being prefixed to the message content. But, in integration engine, the http target message is being prefixed by this XML declaration by default.
Output when tested in Operation Mapping(Desired result):
abc=123:def=456
Output been sent to receiver:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> abc=123:def=456
Is there any possibility to send a HTTP message to the receiver without this XML declartion. In other words, I need only the message content to be sent to the receiver.
Kindly suggest.
Regards,
SwethaHi,
You can use JAVA/or XSLT mapping
See this for Code
Remove Encoding UTF from xml declaration in PI -
Hello friends,
I am trying a ABAP program (posted on SDN) to convert XML into ABAP (internal table) and not having any luck. Either it is my table/structure declaration or XSLT. Could any of you experts give me a hand with it please?
Thanks in advance..but points on help!
Here is my XML:
And my ABAP program:
REPORT ZTESTXMLREAD.
TYPE-POOLS: abap, ixml.
class cl_ixml definition load.
TYPES: BEGIN OF t_dc40,
docnum(17) TYPE C,
status(2) TYPE C,
END OF t_dc40.
TYPES: BEGIN OF t_emkt,
spras(2) TYPE C,
maktx(35) TYPE C,
END OF t_emkt.
TYPES: BEGIN OF t_emrm,
matnr(12) TYPE C,
ersda(8) TYPE C,
ernam(25) TYPE C,
emktx TYPE t_emkt,
END OF t_emrm.
TYPES: BEGIN OF t_mm,
dc40 TYPE t_dc40,
emrm TYPE t_emrm,
END OF t_mm.
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_istream TYPE REF TO if_ixml_istream.
DATA: l_filename TYPE string.
DATA: it_airplus TYPE STANDARD TABLE OF t_mm,
wa_airplus TYPE t_mm.
*Errorvariables
DATA: xslt_err TYPE REF TO cx_xslt_exception,
err_string TYPE string.
PARAMETERS: pa_file TYPE char1024 DEFAULT 'c:Test.XML'.
START-OF-SELECTION.
Creating the main iXML factory
l_ixml = cl_ixml=>create( ).
Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
Creating input stream
l_istream = l_streamfactory->create_istream_uri( 'file://c:Test.xml' ).
here we use the CALL TRANSFORMATION method which calls
TRY.
CALL TRANSFORMATION ZTestXSLT
SOURCE xml l_istream
RESULT xml_output = it_airplus
catch any error, very helpful if the XSLT isn't correct
CATCH cx_xslt_exception INTO xslt_err.
err_string = xslt_err->get_text( ).
WRITE: / 'Transformation error: ', err_string.
EXIT.
ENDTRY.
setting a breakpoint to watch the workarea
by the internal table "it_airplus"
break-point.
LOOP AT it_airplus INTO wa_airplus.
ENDLOOP.Thank you Durairaj, as a matter of fact my program is based on your post (one that you pointed me to). For whatever reason I'm not having luck figuring it out (may be just a bit of work pressure) could you please hlep me a bit more by pointing me to where in my program code/xslt I'm going wrong? I somehow feel that it could be my table structure or xslt.
I would really appreciate it!
Thanks again,
erfan. -
XSLT - Exception error when using XSLT 2.0 code in Transform on LiveCycle ES2
I'm new to using this forum, so apologies in advance in I have posted this to the wrong place.
I'm using Adobe LiveCycle ES2.5 (Jboss) and have written several complex XSLT scripts. All have worked, with the exception of the latest one in which I have to sum a repeating subnode that maynot exist and if it does, may contain a number or be empty. When I have used SUM by itself, it works perfectly if I all the nodes have values, but returns zero if any are missing or are empty. After some searching I found a solution (which I have made bold) in the fragment below.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ...>
<xsl:variable name="varUnitValueTotal" select="sum( (if(SOURCEUNITVALUE='') then 0 else SOURCEUNITVALUE) )"/>
</xsl:stylesheet>
I developed and tested this xslt in XMLSpy 2011 and it works a treat. However, when I invoke the XSLT using the Services\XSLT Transformation 1.0\Transform, I get the following exception error:
javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: Could not find function: if
at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.jav a:936)
at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.j ava:774)
at com.adobe.livecycle.xslt.XsltTransformer.transform(XsltTransformer.java:151)
Now as far as the documentation is concerned ES2 and better should be using XSLT 2.0. However to test a theory I changed the stylesheet version from 2.0 to 1.0 and re-ran the xslt in XMLSpy and it fell over at exactly the same place as the exception error. Which makes me conclude that LC ES2+ is still using XSLT 1.0.
Now I am stuck. The only work around that I can see is to attempt to do the calculation in the form (which sort of defeats the point of usng XSLT). That said I am reluctant to go down that path, since the maintenance overhead is going to be shocking if I have to apply to dozens of forms.
Is there a way to tell the Transform service to use XSLT 2.0 and if so, how and what are the settings? Or do I need to find and use a different transform engine, again if so which one should I use and what settings should I make at either JBoss and/or AdminUI level.
Really hoping that someone can help.The XSLT service is configurable.
http://help.adobe.com/en_US/LiveCycle/9.5/WorkbenchHelp/WS92d06802c76abadb-1cc35bda128261a 20dd-6750.html
1) Stop LiveCycle.
2) Add the .jars of your XSLT processor of choice to the LiveCycle server lib folder.
3) Restart LiveCycle.
4) Go to Workbench and stop the XSLT service. Right-click on XSLTService:1.0 and Edit Service Configuration.
5) Enter the factory name for the given XSLT processor. I think for Xalan 2.7.1 it is org.apache.xalan.processor.TransformerFactoryImpl (but I could be wrong).
6) Restart the service.
Steve -
Generating CDATA containing XML-like text using XSLT Mapper in OFM 11g
Hi,
One of our partners requires XML to be sent as XML string inside a CDATA section. The use of "real" XML is not an option at the moment. We try to generate something like the following using XSLT/XSLT Mapper in SOA Suite 11g:
<element>
<![CDATA[
<supplierElement1>
<supplierElement2>
etcetera
<supplierElement2>
</supplierElement1>
]]>
</element>
We've tried the following two approaches, so far unsuccessful:
<xsl:template match="/">
<inp1:singleString>
<inp1:input>
<xsl:text disable-output-escaping="yes"><![CDATA[test]]></xsl:text>
</inp1:input
</inp1:singleString>
</xsl:template>
resulting in:
<inp1:singleString xmlns:inp1="http://xmlns.oracle.com/singleString">
<inp1:input><![CDATA[test]]></inp1:input>
</inp1:singleString>
and:
<xsl:output method="xml" indent="yes" cdata-section-elements="input"/>
<xsl:template match="/">
<inp1:singleString>
<input>test</input>
</inp1:singleString>
</xsl:template>
resulting in:
<inp1:singleString xmlns:inp1="http://xmlns.oracle.com/singleString" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<input>test</input>
</inp1:singleString>
Does anyone know how to generate the CDATA section declaratively (within XSLT/XSLT Mapper), without resorting to custom code and parsing as we have to do now?
Thanks!
RonaldThe exact error message I'm getting is :
ABAP XML formatting error in XML node of type "element", name: "abap" -
How to ignore prefix from XML while converting XML to csv using XSLT
Hi All,
I am trying to convert XML to csv file.
the XML i have is like....
<?xml version="1.0"?>
<bulkCmConfigDataFile xmlns:es="SpecificAttributes.3.0.xsd" xmlns:un="utranNrm.xsd" xmlns:xn="genericNrm.xsd" xmlns:gn="geranNrm.xsd" xmlns="configData.xsd">
<configData dnPrefix="Undefined">
<xn:SubNetwork id="AU_R">
<xn:SubNetwork id="H5RG_0501">
<xn:MeContext id="Firle_5070020">
<xn:ManagedElement id="1">
<un:RncFunction id="1">
<un:UtranCell id="50390303">
<un:attributes>
<un:userLabel>UtranCell 50390303</un:userLabel>
<un:cId>52383</un:cId>
<un:localCellId>50390303</un:localCellId>
<un:uarfcnUl>9613</un:uarfcnUl>
<un:uarfcnDl>10563</un:uarfcnDl>
<un:primaryScramblingCode>502</un:primaryScramblingCode>
<un:primaryCpichPower>287</un:primaryCpichPower>
<un:maximumTransmissionPower>403</un:maximumTransmissionPower>
<un:primarySchPower>-18</un:primarySchPower>
<un:secondarySchPower>-20</un:secondarySchPower>
<un:bchPower>-20</un:bchPower>
<un:lac>50301</un:lac>
<un:rac>1</un:rac>
<un:sac>52383</un:sac>
<un:utranCellIubLink>SubNetwork=AU_R,SubNetwork=H5RG_0501,MeContext=H5RG_0501,ManagedElement=1,RncFunction=1,IubLink=5039030</un:utranCellIubLink>
</un:attributes>
</un:UtranCell>
</un:RncFunction>
</xn:ManagedElement>
</xn:MeContext>
</xn:SubNetwork>
</xn:SubNetwork>
</configData>
</bulkCmConfigDataFile>now when i am using XSLT functionality to convert this XML into a csv i want ignore all the prefix from this xml like "un" , "xn" etc....
can anybody has idea how i can ignore all this value using XSLTI just dont understand why factory.setIgnoringElementContentWhitespace(true) did not work.That only does something if the XML has a DTD that enables it to know what whitespace can be ignored and what is significant. The API documentation for the method refers you to this document:
http://www.w3.org/TR/REC-xml#sec-white-space -
Problem in transforming XML to string using XSLT
Hi there,
I have a R/3 -> XI -> WebService scenario where the message from XI to webservice needs to be sent in document/wrapped mode (the message xml must be embedded in a string element) and this message needs to be digitally signed.
We are using another webservice to sign the messages, also with the message being sent in a string. To transform the XML's into string and vice-versa, we are using XSLT (/people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping).
The problem is that both the signer and the final webservice understand the special characters (like '<', '>', '&', '"' etc) in one way but the XSLT generates them in another way. For example, the character '<', in both webservices, is returned as "<" but the XSL Transformation results in "<".
The problem now is that our messages are always being rejected because the signature is not being recognized as true, though we are almost 100% sure that it's being done correctly. The only possibility to the error that we found is this character mapping being done differently.
So, it's like this:
XI sends string to signer as "<"
XI receives string from signer as "<"
XI processes the message
XI sends string to webservice as "<"
XI receives string from webservice (containing error message) as "<"
Is there a way of making the XSLT to return "<" instead of "<"?
Thanks in advace,
Henrique.For Java Mapping, you can refer this-
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
In Java Mapping, in the startdocument event , you need to check for the specialchars, and just repalce the value required.
But, what i am thinking is , just try with Java functions inside the XSLT mapping instead of going for Java Mapping. You can call java functions from the XSLT. So before the document starts pasring, you need to replace the special characters. I did not try in XSLT like this.
For this , you can think with this e.g
/people/pooja.pandey/blog/2005/06/27/xslt-mapping-with-java-enhancement-for-beginners
Regards,
Moorthy -
Remove XML declaration header in Oracle
Hi,
is there a way to remove the XML declaration <?xml version="1.0" ?> generated by oracle - ex
- <Envelope>
- <Body>
<?xml version="1.0" ?>
- <MSG09>
to
- <Envelope>
- <Body>
- <MSG09>
ThanksHi,
is there a way to remove the XML declaration <?xml version="1.0" ?> generated by oracle - ex
- <Envelope>
- <Body>
<?xml version="1.0" ?>
- <MSG09>
to
- <Envelope>
- <Body>
- <MSG09>
Thanks -
SAP 4.7 XML data exchange using XSLT
Hello All,
Hopefully the right place to post such article but here goes any way.
My project involves producing XML files and then reading them back into to SAP internal tables. I am ok with writing SAP data to external XML file but reading it back in is causing a lot of head scratching.
I am able to double click the XML file and it launches Ok in Internet Explorer.
I am also able to debug the xslt file from within SE80 and the correct output is displayed.
However, where I am trying to read the contents of the xml file via the Call Transformation procedure call my output table is not getting populated but instead I am recieving an error message saying the following is not correct:
xmlns:sapxsl="http://www.sap.com/sapxsl
but the above line is placed automaticlly in the XSLT when you create a new one from within SE80.
I am new to SAP ABAP development so not sure what's exactly wrong.
Any help on this issue will be greatfully appreciated. Thanks in Advance,
Wasif
REPORT z_hp_xml_test .
TYPE-POOLS: ixml.
TABLES: tstc, tstct.
TYPES: BEGIN OF ty_transactions,
tcode LIKE tstc-tcode,
ttext LIKE tstct-ttext,
sprsl LIKE tstct-sprsl,
END OF ty_transactions.
DATA: itab_transactions TYPE STANDARD TABLE OF ty_transactions.
TYPES: BEGIN OF t_xml_line,
data(256) TYPE x,
END OF t_xml_line.
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_parser TYPE REF TO if_ixml_parser,
l_istream TYPE REF TO if_ixml_istream,
l_document TYPE REF TO if_ixml_document,
l_node TYPE REF TO if_ixml_node,
l_xmldata TYPE string.
DATA: l_elem TYPE REF TO if_ixml_element,
l_root_node TYPE REF TO if_ixml_node,
l_next_node TYPE REF TO if_ixml_node,
l_name TYPE string,
l_iterator TYPE REF TO if_ixml_node_iterator.
DATA: l_xml_table TYPE TABLE OF t_xml_line,
l_xml_line TYPE t_xml_line,
l_xml_table_size TYPE i.
DATA: l_filename TYPE string.
PARAMETERS: pa_file TYPE char1024 DEFAULT 'C: emp ransactions.xml'.
Validation of XML file: Only DTD included in xml document is supported
PARAMETERS: pa_val TYPE char1 AS CHECKBOX.
START-OF-SELECTION.
Creating the main iXML factory
l_ixml = cl_ixml=>create( ).
Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
PERFORM get_xml_table CHANGING l_xml_table_size l_xml_table.
wrap the table containing the file into a stream
l_istream = l_streamfactory->create_istream_itable( table =
l_xml_table
size =
l_xml_table_size ).
Creating a document
l_document = l_ixml->create_document( ).
Create a Parser
l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
istream = l_istream
document = l_document ).
Validate a document
IF pa_val EQ 'X'.
l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
ENDIF.
Parse the stream
If any errors then disply else convert XML to table
IF l_parser->parse( ) NE 0.
IF l_parser->num_errors( ) NE 0.
DATA: parseerror TYPE REF TO if_ixml_parse_error,
str TYPE string,
i TYPE i,
count TYPE i,
index TYPE i.
count = l_parser->num_errors( ).
WRITE: count, ' parse errors have occured:'.
index = 0.
WHILE index < count.
parseerror = l_parser->get_error( index = index ).
i = parseerror->get_line( ).
WRITE: 'line: ', i.
i = parseerror->get_column( ).
WRITE: 'column: ', i.
str = parseerror->get_reason( ).
WRITE: str.
index = index + 1.
ENDWHILE.
ENDIF.
ELSE.
TRY .
CALL TRANSFORMATION (`Z_HP_TEST_XSLT`)
SOURCE XML l_xml_table
RESULT outtab = itab_transactions.
DATA: xslt_err TYPE REF TO cx_xslt_exception .
CATCH cx_xslt_exception INTO xslt_err.
DATA: s TYPE string.
s = xslt_err->get_text( ).
WRITE: ': ', s.
STOP.
ENDTRY .
Process the document
IF l_parser->is_dom_generating( ) EQ 'X'.
PERFORM process_dom USING l_document.
ENDIF.
ENDIF.
*& Form get_xml_table
FORM get_xml_table CHANGING l_xml_table_size TYPE i
l_xml_table TYPE STANDARD TABLE.
Local variable declaration
DATA: l_len TYPE i,
l_len2 TYPE i,
l_tab TYPE tsfixml,
l_content TYPE string,
l_str1 TYPE string,
c_conv TYPE REF TO cl_abap_conv_in_ce,
l_itab TYPE TABLE OF string.
l_filename = pa_file.
upload a file from the client's workstation
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = l_filename
filetype = 'BIN'
IMPORTING
filelength = l_xml_table_size
CHANGING
data_tab = l_xml_table
EXCEPTIONS
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Writing the XML document to the screen
CLEAR l_str1.
LOOP AT l_xml_table INTO l_xml_line.
c_conv = cl_abap_conv_in_ce=>create( input = l_xml_line-data
replacement = space ).
c_conv->read( IMPORTING data = l_content len = l_len ).
CONCATENATE l_str1 l_content INTO l_str1.
ENDLOOP.
l_str1 = l_str1+0(l_xml_table_size).
SPLIT l_str1 AT cl_abap_char_utilities=>cr_lf INTO TABLE l_itab.
WRITE: /.
WRITE: /' XML File'.
WRITE: /.
LOOP AT l_itab INTO l_str1.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab
IN
l_str1 WITH space.
WRITE: / l_str1.
ENDLOOP.
WRITE: /.
ENDFORM. "get_xml_table
*& Form process_dom
FORM process_dom USING document TYPE REF TO if_ixml_document.
DATA: node TYPE REF TO if_ixml_node,
iterator TYPE REF TO if_ixml_node_iterator,
nodemap TYPE REF TO if_ixml_named_node_map,
attr TYPE REF TO if_ixml_node,
name TYPE string,
prefix TYPE string,
value TYPE string,
indent TYPE i,
count TYPE i,
index TYPE i.
node ?= document.
CHECK NOT node IS INITIAL.
ULINE.
WRITE: /.
WRITE: /' DOM-TREE'.
WRITE: /.
IF node IS INITIAL. EXIT. ENDIF.
create a node iterator
iterator = node->create_iterator( ).
get current node
node = iterator->get_next( ).
loop over all nodes
WHILE NOT node IS INITIAL.
indent = node->get_height( ) * 2.
indent = indent + 20.
CASE node->get_type( ).
WHEN if_ixml_node=>co_node_element.
element node
name = node->get_name( ).
nodemap = node->get_attributes( ).
WRITE: / 'ELEMENT :'.
WRITE: AT indent name COLOR COL_POSITIVE INVERSE.
IF NOT nodemap IS INITIAL.
attributes
count = nodemap->get_length( ).
DO count TIMES.
index = sy-index - 1.
attr = nodemap->get_item( index ).
name = attr->get_name( ).
prefix = attr->get_namespace_prefix( ).
value = attr->get_value( ).
WRITE: / 'ATTRIBUTE:'.
WRITE: AT indent name COLOR COL_HEADING INVERSE, '=',
value COLOR COL_TOTAL INVERSE.
ENDDO.
ENDIF.
WHEN if_ixml_node=>co_node_text OR
if_ixml_node=>co_node_cdata_section.
text node
value = node->get_value( ).
WRITE: / 'VALUE :'.
WRITE: AT indent value COLOR COL_GROUP INVERSE.
ENDCASE.
advance to next node
node = iterator->get_next( ).
ENDWHILE.
ENDFORM. "process_dom
Section 3: My XSLT file:
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sapxsl="http://www.sap.com/sapxsl"
<xsl:strip-space elements="*"/>
<xsl:template match="TransList">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Tcode">
Tcode <xsl:apply-templates />
</xsl:template>
<xsl:template match="ttext">
ttext <xsl:apply-templates />
</xsl:template>
<xsl:template match="sprsl">
sprsl <xsl:apply-templates />
</xsl:template>
</xsl:transform>The exact error message I'm getting is :
ABAP XML formatting error in XML node of type "element", name: "abap" -
How to find XSD file? XML to ABAP using XSLT convertor
Hi Gurus,
I am trying to convert an XML file to ABAP internal tables using an XSLT transformation. I used the code posted by Durairaj (XSLT program Y_XML_2_ITAB_SIMPLE as mentioned in the link: [Y_XML_2_ITAB_SIMPLE|Parse data to Internal Table;) and the code worked fine.
My XML file structure is different, and when I try to modify the code for my purposes I got stuck. While changing the XML file strings in the report, I am unable to replace the tag xsi:noNamespaceSchemaLocation="invoice_btm.xsd" correctly. I am also not sure what this file "invoice_btm.xsd" does and where it is stored. When I remove the tag, I get other errors and cannot proceed ahead.
Can you please advice as to how I should proceed? Also, where can I see the XSD file? can I add a XSD file for my own XML? Or, is there a way to eliminate the need for an XSD file altogether?
Thanks in advance.
Regards,
Shailesh.Hi guys,
Any help would be most helpful. Thanks again,
Hi guys,
Any ideas on this issue? Thanks again for your help.
Hi Naimesh,
Thanks for the quick reply. I am getting the error "The element abap was expected for the XML-ABAP transformation". I have replaced the following:
1) "INVOICES_BTM" with the string "ACCOUNT_INFO"
2) "INVOICE_BTM" with the string "ROOTNODE"
My XSLT:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:template match="ACCOUNT_INFO">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<OUTPUT>
<xsl:for-each select="ROOTNODE">
<items>
<INV_DATE>
<xsl:value-of select="INVOICE_HEAD/INVOICE_DATE"/>
</INV_DATE>
<INV_NO>
<xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/NUMBER"/>
</INV_NO>
<INV_EXT>
<xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/EXTENSION"/>
</INV_EXT>
<INV_SEQ>
<xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/SEQUENCE"/>
</INV_SEQ>
</items>
</xsl:for-each>
</OUTPUT>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>
My XML program:
TYPES: BEGIN OF stru,
inv_date(10),
inv_no(50),
inv_ext(10),
inv_seq(10),
END OF stru.
DATA: outtab TYPE STANDARD TABLE OF stru .
DATA: xslt_error TYPE REF TO cx_xslt_exception,
xslt_message TYPE string .
DATA: xml_string TYPE string .
CLEAR xml_string .
CONCATENATE
'<?xml version="1.0" encoding="ISO-8859-1"?>'
'<ACCOUNT_INFO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ROOTNODE.xsd">'
'<ROOTNODE>'
'<INVOICE_HEAD LANGUAGE="DE" DIRECT_DEBIT_QUALIFIER="NO">'
'<INVOICE_DATE>20040112</INVOICE_DATE>'
'<INVOICE_NUMBER>'
'<NUMBER>0306299999</NUMBER>'
'<EXTENSION>1</EXTENSION>'
'<SEQUENCE>01</SEQUENCE>'
'</INVOICE_NUMBER>'
'</INVOICE_HEAD>'
'</ROOTNODE>'
'<ROOTNODE>'
'<INVOICE_HEAD LANGUAGE="DE" DIRECT_DEBIT_QUALIFIER="NO">'
'<INVOICE_DATE>20040113</INVOICE_DATE>'
'<INVOICE_NUMBER>'
'<NUMBER>0306299888</NUMBER>'
'<EXTENSION>2</EXTENSION>'
'<SEQUENCE>02</SEQUENCE>'
'</INVOICE_NUMBER>'
'</INVOICE_HEAD>'
'</ROOTNODE>'
'</ACCOUNT_INFO>'
INTO xml_string .
TRY .
CALL TRANSFORMATION ('ZH2_XML_TRANS_I1')
SOURCE XML xml_string
RESULT output = outtab.
CATCH cx_xslt_exception INTO xslt_error.
xslt_message = xslt_error->get_text( ).
ENDTRY.
break-point.
Edited by: Shailesh S Kamath on Jan 16, 2012 2:17 PM
Edited by: Shailesh S Kamath on Jan 30, 2012 2:47 PM -
Problems with some web parts when using XSLT
I have a page on which I have several web parts. Some web parts are custom while others are OOB and only XSLT is applied on them.
I am using 2 WFEs with NLB. Problem is when I do iisreset on one of the WFE then the OOB web parts with XSLT start giving error. You know the standard error "corelation ID....bla bla bla". Anyway the error automatically goes away after a 2, 3 minutes.
So basically if I do iisreset or stop the iis, and then load that page, then all custom web parts load fine except those OOB web parts with XSLT. And then they too start working fine after 2, 3 minutes if I reload page.
What could be the reason for that? Looks like some service on which XSLT depends take time to load!? And once that service is loaded then they start working fine? Or it could be due to distributed cache or something!?Hi Frank,
Which version of the SharePoint 2010 did you use?
In June 2011 CU code was added to the DataFormWebPart (which is used to display list data) that if an XSLT transform took longer than 5 seconds, a StackOverflowException was thrown. This was done to avoid
a potential Denial Of Service attack on SharePoint if crafted XML could be sent that would continually clog up the XSLT, thereby stopping pages from rendering.
In August 2011 CU the transform "timeout" was reduced from 5 seconds to 1.
So, any list with XSLT that takes longer than 1 second to parse in an XSLT transform goes *boom*.
After you perform an IIS reset , the cache of the page was cleared and you encountered the error. Once the page is cached, there is no error.
You can try to set up XSLT Timeout with the following PS commands:
$farm = Get-SPFarm
$farm.XsltTransformTimeOut = 5
$farm.Update()
Reference:
http://social.msdn.microsoft.com/Forums/sharepoint/de-DE/44cfd798-be7a-4436-8786-bd44049e7def/sp2010-column-filter-causing-unable-to-display-web-part-error-and-a-stack-overflow-exception?forum=sharepointgeneralprevious
Best Regards,
Eric
Eric Tao
TechNet Community Support -
Is there a way to get the actual XML string when using the JAXP SAX Parser?
Hi All,
I am using a JAXP SAX xml parser and am looking for a way to get the actual line of xml that is being parsed from within a content handler.
Here's my scenario. Consider the following example xml document.
<formCollection>
<form name="myForm">
<text/>
<selection/>
</form>
<form name="anotherForm">
<text/>
</form>
</formCollection>My hope is to validate the entire document and then insert an xml string containing each "form" element (and its sub-elements) into a map for later use. My thought was to create a String as each "form" element is being parsed (begining with the form's startElement event and concatenating until the form's endElement event is reached) and then inserting this string into the map. Is there a way to get the actual line of xml that is being parsed, rather than just the element name and attribute values?DrClap wrote:
YouRang wrote:
2. The first handler would validate the entire XML document, extract the "type" attribute from each <form> element, and place each <form> element and its sub-elements into the map of Strings, using the "type" attribute as the key. The second handler would take a <form> element and parse it into a Form object for the display. This option was the impetus for my question because it relies on the first handler being able to access the entire <form> element XML String and write it to a map.I don't see why you need the raw data from the XML document here. You should already be abstracting your data into Java classes in the first handler, instead of making the second handler do the parsing all over again.Correct, I am not referring to XForms. In this case, it happens that I am using the XML to generate an SWT ScrolledForm object and, thus, the XML element name happens to be named "form." However, the concept/design problem could apply to any type of object and the XML element could be appropriately renamed.
My experience with XSLT is limited and I haven't done anything with it for several years. With that said, it seems that it is primarily used for generating web content, which wouldn't apply in this case because this is for a client-server application. I could be off base on this one -- if XSLT applies to much broader translations and would be more appropriate for generating Java objects than my current methodology, I could certainly look into it further.
I apologize that option two didn't make more sense; it is difficult to explain. Yes, optimally the data should be abstracted into Java classes in the first handler. This is really an elaboration that I failed to specify when explaining option one. The problem is that the user can choose to create any number of "forms" of any type. For instance, let's say that from the File -> New menu there are options for seven different types of forms and each form is used to send completely different data. The user can select form1, select form1 again, select form4, and select form7 (or any other combination) and bring up tabs that display the different forms. The user can then enter data and submit each form separately. When the user selects File -> New -> FormX, a SWT ScrolledForm object that corresponds with FormX must be given to the display. Because SWT ScrolledForm objects do not allow a deep copy, I cannot simply read the XML <form> elements at initialization, parse them into ScrolledForm objects, and pass deep copies of the ScrolledForm objects to the display each time the user clicks File -> New -> FormX. The only simple way I see of getting a new copy of a ScrolledForm object is to reparse the appropriate XML <form> element in order to create one each time the user selects File -> New -> FormX. As such, one handler would need to read the entire XML document and parse the <form> elements into a map (or some other data structure) and another handler would need to parse individual <form> elements into SWT ScrolledForm objects. The first handler would be called at initialization and the second handler would be called each time a user clicked on File -> New -> FormX. Once again, this isn't exactly my favorite implementation... but seems the simplest given that there is no way to do a deep copy of an SWT ScrolledForm object. Hopefully that makes a little more sense. No worries if it doesn't -- I just figured I'd throw this out there and see if anyone had a better idea. -
Hi,
I am transforming some XML using Transformer class. I get the following output:
XML Document transformed to:
<?xml version="1.0" encoding="UTF-8"?>
<VOTBEndpoint schemaVersion="1.00"><a n="id" v="jobmanager.fork" /><a n="Username" v="UserX" /><a n="spool.directory" v="/tmp" /></VOTBEndpoint>I don't want the first tag the, <?xml?>, does it have to stay in this document as I want very lightweight output, every byte counts.
I thought the statements:
Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltView));
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes")
// Run the transformation
JDOMSource source = new JDOMSource(doc);
JDOMResult result = new JDOMResult();
transformer.transform(source, result);
//Return transformed document
return result.getDocument();I thought this code would have produced the output I wanted. If the XML tag must stay do you know how I can remove the carriage return the docuement places after this statement as I later convert the JDOM document to a string using XMLOutputter - it is really this stary \n that is cauing major issues - I could live with th e<xml> tag.
Cheers -Hi Thanks for your response,
Sorry I couldn't reply earlier I now have:
Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltView));
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");With both these declarations is still get the following output:
<?xml version="1.0" encoding="UTF-8"?>
<VOTBEndpoint schemaVersion="1.00"><a n="id" v="jobmanager.fork" /><a n="Username" v="UserX" /><a n="spool.directory" v="/tmp" /></VOTBEndpoint>I'll explain why this is annoying - this XML gets turned into a string using XMLOutputter then transported over the network using a messaging system (capable of transporting string values). Once this message gets to it's destination it needs to be reconverted to XML.
This <XML> tag the transformer inserts has carriage returns after it which is casuing a problem so I figure I have two options:
* Stop the <XML> tag from being outputted and then reconvert with SAX Builder
* Once XML converted to a String remove the carriage returns manually using String.replace (NOTE: tried this method and transports fine but wont reconvert to XML using SAXBuilder. Exception occurs with message XML Construction Failed)
If you can help with either - stop XML tag appearing or explain why the SAX Builder at the destination cannot convert back to XML i'd be most grateful!
XML SAX cannot convert below (after option 1: manually removed carriage returns, all one line):
<?xml version="1.0" encoding="UTF-8"?>
<VOTBEndpoint schemaVersion="1.00"><a n="id" v="jobmanager.fork" /><a n="Username" v="UserX" /><a n="spool.directory" v="/tmp" /></VOTBEndpoint>And here is the code I'm using to convert:
public String getMessageXMLAttributeValue(String attributeName) throws Exception{
SAXBuilder builder = new SAXBuilder();
XMLOutputter out = new XMLOutputter();
try {
Document doc = builder.build(getMessageXMLPayload()); //here is where error is occurring!! method returns string value to build
out.outputString(doc);//debug
String val = (String) XPath.selectSingleNode(doc, "//a[@n='id']/@v");//this would be the attributreName field but just testing
System.out.println(attributeName + " Attribute xpath'd as " + val);
return val;
} catch (JDOMException ex) {
ex.printStackTrace();
return null;
} catch (Exception ex){
ex.printStackTrace();
throw new Exception("Unspecfied Exception occurred: getSchemaAttribute " + attributeName);
} -
Replace xml code when used as a xmltype converted from clob.
I am still new at all this so I will try to make sense.
I have the "sys_xmlgen" where it takes my clob_content which is a clob and converts it into the v_xml which is xmltype.
****code to show change of clob to xmltype.
SELECT sys_xmlgen(clob_content) INTO v_xml FROM xmltest2 WHERE item_id = v_item_id;
update xmltest2 set xml = v_xml where item_id = v_item_id;
**end of code
When you use sys_xmlgen it changes the xml into this example:
<?xml version="1.0"?>
<CLOB_CONTENT><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE metadata SYSTEM "csdgm2.dtd">
<?xml-stylesheet href="FGDC_V2.xsl" type="text/xsl"?>
<metadata>
<idinfo>
</CLOB_CONTENT>
I need to remove the <CLOB_CONTENT> tag and change some things such as the "<" to a "<" and so on. But when I do a replace statement
select replace(clob_content, '<', '<') into v_xml from xmltest2;
It says I can not do a clob into number.
Just to make myself clear, the clob_content is clob and v_xml is xmltype. SOOO I think that is where my problem is. Does anyone know the syntax to replace the code in my xml so that it looks like the original clob xml??
Any help would be appreciated.I am still new at all this so I will try to make sense.
I have the "sys_xmlgen" where it takes my clob_content which is a clob and converts it into the v_xml which is xmltype.
****code to show change of clob to xmltype.
SELECT sys_xmlgen(clob_content) INTO v_xml FROM xmltest2 WHERE item_id = v_item_id;
update xmltest2 set xml = v_xml where item_id = v_item_id;
**end of code
When you use sys_xmlgen it changes the xml into this example:
?xml version="1.0"?>
<CLOB_CONTENT><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE metadata SYSTEM "csdgm2.dtd">
<?xml-stylesheet href="FGDC_V2.xsl" type="text/xsl"?>
<metadata>
<idinfo>
<citation>
<citeinfo></CLOB_CONTENT>
I need to remove the <CLOB_CONTENT> tag and change some things such as the "<" to a "<" and so on. But when I do a replace statement
select replace(clob_content, '<', '<') into v_xml from xmltest2;
It says I can not do a clob into number.
Just to make myself clear, the clob_content is clob and v_xml is xmltype. SOOO I think that is where my problem is. Does anyone know the syntax to replace the code in my xml so that it looks like the original clob xml??
Any help would be appreciated.
Maybe you are looking for
-
Complicated PL/SQL questions that involves function with in type parameter
Hello, I have a question about functions with in-parameters. In the HR schema, I need to get the minimum salary of the job_id that is mentioned as an in-parameter. this is what I am thinking but I dont know if it's correct or not or what should I do
-
Pixels Missing when I continuously rasterize AI layer
Hi, I am having trouble finding a solution to my exact problem on other forums. I'm using After Effects CC and have imported all of the files from Adobe Illustrator CC. For some reason, when I click the "continuously rasterize" option for some of the
-
Adobe PDF/X-1a:2001/2003/2008 and International Guidelines
Hi all, First of all, forgive me for any incompetence - I'm extremely new to the world of graphic design and print compatibility. System information: 64-bit Windows 7 running Adobe Illustrator CS6 version 16.1.1 (64-bit) I am currently formatting our
-
Java interface with xml communication
Hello everybody, For a project i need to make a java interface with xml communication. For example ; from 1 laptop I press on a java button and then i need to get a text message on the other laptop. The java interface is already created now the xml c
-
Has anybody had success implementing iPhoto on a Drobo (FS)? I have had good luck with iTunes on the Drobo and now want to use the Drobo for iPhoto. Thanks Gary