Quantcast
Channel: SCN : All Content - ABAP Development
Viewing all articles
Browse latest Browse all 8332

Handling unexpected XML tags in an ST Simple Transformation

$
0
0

Hi all,

 

I am writing an ST program to parse an incoming XML string, and I want to know if there is a way to make it flexible enough to make it able to handle new XML tags in the input stream, if the source system changes their XML structure.

 

For example, suppose that my program needs to get the street address, city, and state from the following XML stream.
 
<Address>
  <Street>330 RATHBURN RD WEST</Street>
  <City>Chicago</City>
  <State>IL</State>
</Address>

 

I can easily code that part with ST logic such as

 

<Street>
  <tt:value ref="abap_street"/>
</Street>

<City>
  <tt:value ref="abap_city"/>
</City>

<State>
  <tt:value ref="abap_state"/>
</State>


But further suppose that the system sending me the XML stream makes a change to include apartment numbers in their address format, such as:

 

<Address>
  <Street>330 RATHBURN RD WEST</Street>
  <Apartment>27</Apartment>
  <City>Chicago</City>
  <State>IL</State>
</Address>


I do not need to capture the apartment number, but I want my ST program to be able to run without crashing if an unexpected tag like that occurs. 

 

I know that I can capture a cx_st_match_element exception and keep my ABAP program from crashing, but that does not let me parse through to the end of the XML stream and get all the data I need.  I want the ST code to be able to capture the data from all expected XML tags and ignore the unexpected tags without raising an exception.

 

Is that possible?   

 

Thanks

 

Gord


Viewing all articles
Browse latest Browse all 8332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>