2016 Mar 16 7:53 AM
Hi folks,
Which method is used to get below xml structure.
<DeletedECN STATUS="0" TYPE="Unknown" NAME="DeletedECN"> </DeletedECN>
Thanks,
darshan
2016 Mar 16 10:06 AM
Hi,
*----------------------------------------------------------------------*
FORM test_03 .
DATA: ob_ixml TYPE REF TO if_ixml . " Interface of Factory Object
DATA: ob_ixml_document TYPE REF TO if_ixml_document, " XML Document in DOM Representation
ob_ixml_encoding TYPE REF TO if_ixml_encoding. " Character Encoding
ob_ixml = cl_ixml=>create( ).
ob_ixml_document = ob_ixml->create_document( ).
DATA: ob_ixml_element TYPE REF TO if_ixml_element . " Element of an XML Document
ob_ixml_element = ob_ixml_document->create_simple_element(
name = 'DeletedECN'
parent = ob_ixml_document ) .
ob_ixml_element->set_attribute( EXPORTING name = 'TYPE' value = 'Unknown' ) .
ob_ixml_element->set_attribute( EXPORTING name = 'NAME' value = 'DeletedECN' ) .
* ob_ixml_element->set_value( ' ' ) .
DATA: ob_ixml_stream_factory TYPE REF TO if_ixml_stream_factory. " Factory for Streams
DATA: ob_ostream TYPE REF TO if_ixml_ostream . " Output Streams
DATA: debug TYPE string.
* For debug purpose only
ob_ixml_stream_factory = ob_ixml->create_stream_factory( ).
ob_ostream = ob_ixml_stream_factory->create_ostream_cstring( debug ).
ob_ostream->set_pretty_print( abap_true ).
ob_ixml_document->render( ostream = ob_ostream ) .
* At this point we have XML
* Look at debug using the XML view .
* See the content of count vs the XML output using tabular view
BREAK-POINT .
ENDFORM.
*----------------------------------------------------------------------*
2016 Mar 16 8:17 AM
2016 Mar 16 9:06 AM
Hi Horst,
I am using below code:
lv_string3 = 'DeletedECN STATUS="0" TYPE="Unknown" NAME="DeletedECN"'.
ref3_ixml_element = ref_ixml_document->create_element(
name = lv_string3 ).
ref_ixml_node_parent->append_child( new_child = ref3_ixml_element ).
through which i am getting
<DeletedECN STATUS="0" TYPE="Unknown" NAME="DeletedECN">
2016 Mar 16 10:06 AM
Hi,
*----------------------------------------------------------------------*
FORM test_03 .
DATA: ob_ixml TYPE REF TO if_ixml . " Interface of Factory Object
DATA: ob_ixml_document TYPE REF TO if_ixml_document, " XML Document in DOM Representation
ob_ixml_encoding TYPE REF TO if_ixml_encoding. " Character Encoding
ob_ixml = cl_ixml=>create( ).
ob_ixml_document = ob_ixml->create_document( ).
DATA: ob_ixml_element TYPE REF TO if_ixml_element . " Element of an XML Document
ob_ixml_element = ob_ixml_document->create_simple_element(
name = 'DeletedECN'
parent = ob_ixml_document ) .
ob_ixml_element->set_attribute( EXPORTING name = 'TYPE' value = 'Unknown' ) .
ob_ixml_element->set_attribute( EXPORTING name = 'NAME' value = 'DeletedECN' ) .
* ob_ixml_element->set_value( ' ' ) .
DATA: ob_ixml_stream_factory TYPE REF TO if_ixml_stream_factory. " Factory for Streams
DATA: ob_ostream TYPE REF TO if_ixml_ostream . " Output Streams
DATA: debug TYPE string.
* For debug purpose only
ob_ixml_stream_factory = ob_ixml->create_stream_factory( ).
ob_ostream = ob_ixml_stream_factory->create_ostream_cstring( debug ).
ob_ostream->set_pretty_print( abap_true ).
ob_ixml_document->render( ostream = ob_ostream ) .
* At this point we have XML
* Look at debug using the XML view .
* See the content of count vs the XML output using tabular view
BREAK-POINT .
ENDFORM.
*----------------------------------------------------------------------*
2016 Mar 16 12:27 PM
Hi Eitan,
thank you for your reply.
i understood your solution.
but i am unable to get last closing node i.e. </DeletedECN>
<DeletedECN STATUS="0" TYPE="Unknown" NAME="DeletedECN"> </DeletedECN>..
how can i achieve this.
Thanks,
Darshan.
2016 Mar 16 12:32 PM
Hi Darshan,
I have faced this issue before. What I observed is, SAP uses a "self-closing tag" in case there are no elements under the node. I haven't found out a setting on SAP to make it generate a closing tag.
Ref: XML Elements
Thanks, Juwin
2016 Mar 16 12:33 PM
Look at the picture from Eitan. The Tag is closed at the end, it does not need to have separate closing...
2016 Mar 16 12:37 PM
2016 Mar 16 12:38 PM
Hi,
This is a valid XML .
Since you do no use any value there is no closing tag .
If you use it:
You get:
There might be an option to force the ob_ostream to produce a closing tag but I do not see it.
Regards.
2016 Mar 16 12:47 PM
2016 Mar 16 12:57 PM
Hi Eitan,
I appreciate your help,,
How can i get status attribute?.
Thanks,
Darshan
2016 Mar 16 1:02 PM
2016 Mar 16 1:02 PM
Add one more attribute just like he has given in the sample code:
ob_ixml_element->set_attribute( exporting name = 'STATUS' value = '0' )
Thanks,
Juwin
2016 Mar 16 1:09 PM
2016 Mar 16 1:18 PM
2016 Mar 16 1:26 PM
Or better add some unique dummy value like "[SAP_DUMMY]".
And clear it from XLM string at the end.
2016 Mar 16 1:31 PM
Hi Darshan,
It does appear. Complete code is:
1 report xmlexample.
2
3 data:ob_ixml type ref to if_ixml . " Interface of Factory Object
4 data:ob_ixml_document type ref to if_ixml_document, " XML Document in DOM Representation
5 ob_ixml_encoding type ref to if_ixml_encoding. " Character Encoding
6
7 ob_ixml = cl_ixml=>create( ).
8
9 ob_ixml_document = ob_ixml->create_document( ).
10
11 data:ob_ixml_element type ref to if_ixml_element . " Element of an XML Document
12
13 ob_ixml_element = ob_ixml_document->create_simple_element(
14 name = 'DeletedECN'
15 parent = ob_ixml_document ) .
16
17 ob_ixml_element->set_attribute( exporting name = 'STATUS' value = '0' ) .
18
19 ob_ixml_element->set_attribute( exporting name = 'TYPE' value = 'Unknown' ) .
20
21 ob_ixml_element->set_attribute( exporting name = 'NAME' value = 'DeletedECN' ) .
22 data: value type string value cl_abap_char_utilities=>newline.
23 ob_ixml_element->set_value( value ) .
24
25 data:ob_ixml_stream_factory type ref to if_ixml_stream_factory. " Factory for Streams
26 data:ob_ostream type ref to if_ixml_ostream . " Output Streams
27
28 data:debug type string.
29
30 * For debug purpose only
31 ob_ixml_stream_factory = ob_ixml->create_stream_factory( ).
32 ob_ostream = ob_ixml_stream_factory->create_ostream_cstring( debug ).
33 ob_ostream->set_pretty_print( abap_true ).
34 ob_ixml_document->render( ostream = ob_ostream ) .
35
36 * At this point we have XML
37 * Look at debug using the XML view .
38 * See the content of count vs the XML output using tabular view
39 write debug.
Thanks,
Juwin
2016 Mar 16 1:39 PM
With the newline character, there is no need to do a replace/ clear at the end. So, isn't that actually better?
Thanks, Juwin
2016 Mar 16 1:47 PM
Hi juwin,
I am using show_xml for display..
ref12_ixml_element = ref_ixml_document->create_simple_element(
name = 'DeletedAlternateLinks '
parent = ref_ixml_document ).
ref12_ixml_element->set_attribute( EXPORTING name = 'STATUS' value = '0' ) .
ref12_ixml_element->set_attribute( EXPORTING name = 'TYPE' value = 'Unknown' ) .
ref12_ixml_element->set_attribute( EXPORTING name = 'Name' value = 'DeletedAlternateLinks ' ) .
ref12_ixml_element->set_value( c_newline ).
ref_ixml_node_parent->append_child( new_child = ref12_ixml_element ).
Thanks,
Darshan
2016 Mar 16 1:57 PM
This could be a display issue with the viewer. Open the downloaded XML file, using a notepad and then check for the closing tags in notepad.
Thanks, Juwin
2016 Mar 16 1:59 PM
It is unnecessary character in the output XML.
Might cause problems with some XML parsers (even though it should not).
For example IE shows it parsed like this:
<to> </to> (with space between)
Chrome:
<to></to> (without space)
and other IE (older):
<to />
And it will obviously create new line if displayed in simple text editors.
2016 Mar 16 2:00 PM
It is just because of parser.
Raw data (XML string) contains closing tag. You can see it even in your screenshot (debugger)
2016 Mar 16 2:04 PM
ok juwin..
i am using below code for display...
CALL FUNCTION 'SDIXML_DOM_TO_XML'
EXPORTING
document = ref_ixml_document
IMPORTING
xml_as_string = lv_xstring
EXCEPTIONS
no_document = 1
OTHERS = 2.
IF sy-subrc <> 0.
**--Exception Handling
ENDIF.
**--convert xstring to string
CALL METHOD cl_abap_conv_in_ce=>create
EXPORTING
encoding = 'UTF-8'
endian = 'L'
ignore_cerr = 'X'
replacement = '#'
input = lv_xstring " Xstring
RECEIVING
conv = convin.
CALL METHOD convin->read
IMPORTING
data = lv_xml.
cl_abap_browser=>show_xml(
EXPORTING
xml_string = lv_xml ).
what modification i need to do to download xml..
please help.
Thanks,
Darshan
2016 Mar 16 2:09 PM
You should be able to convert the XML string to a character table using CONVERT_STRING_TO_TABLE and then just use GUI_DOWNLOAD, to get the file out.
Thanks, Juwin
2016 Mar 16 2:15 PM
2016 Mar 16 2:41 PM
2016 Mar 17 6:12 AM
2016 Mar 17 7:16 AM
Hi Eitan,
How to bring STATUS attribute at beginning...
Thanks,
Darshan
2016 Mar 17 7:35 AM
Hi Eitan ,
My status = '0' is not at the beginning irrespective of its position..
Thanks,
Darshan