2012 Oct 04 2:10 PM
Hi all,
my provider sends me an XML document, which I try to parse with simple transformation
My problem is the following part:
<identifier>
<key name="curvename" tt:value-ref="CURVENAME"/>
<key name="group" tt:value-ref="GROUP"/>
</identifier>
Sometimes i get the line with curvename, sometimes the line with group, or I got both.
If curvename is missing I got an exception CX_ST_MATCH_TEXT
How can I prevent this.
Best regards Marcus
2012 Oct 04 3:03 PM
Hi,
You can use <tt:cond frq="?"> within <tt:group>.
More info: SAP Help on ST grouping
Have a look at attached examples, the ST will process them all filling a structure with two fields a and b.
Kind Regards,
Jeroen.
2012 Oct 04 3:03 PM
Hi,
You can use <tt:cond frq="?"> within <tt:group>.
More info: SAP Help on ST grouping
Have a look at attached examples, the ST will process them all filling a structure with two fields a and b.
Kind Regards,
Jeroen.
2012 Oct 04 3:24 PM
Hi Jeroen,
thanks, but it does not work
<identifier>
<tt:group>
<tt:cond frq="?">
<key name="curvename" tt:value-ref="CURVENAME"/>
</tt:cond>
<tt:cond frq="?">
<key name="group" tt:value-ref="GROUP"/>
</tt:cond>
</tt:group>
</identifier>
I tink the problem is caused by same tag <key> and only different attribut values for attribut name.
Kind regards
Marcus
2012 Oct 04 3:59 PM
Hi,
Sorry, I thought it was about optional elements.
For attributes of an element, it's similar.
Apply the grouping and the cond on the attributes.
Check example. Element a has two attributes, att1 and att2.
The simple transformation will process both without errors.
Kind Regards,
Jeroen
2012 Oct 04 4:12 PM
Hi,
FYI: the tt:cond is also working without tt:group. It is often just in a tt:group scenario but it's not mandatory...
This will also work:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<identifier>
<a>
<tt:cond>
<tt:attribute name="att1" value-ref="root.a"/>
</tt:cond>
<tt:cond>
<tt:attribute name="att2" value-ref="root.b"/>
</tt:cond>
</a>
</identifier>
</tt:template>
</tt:transform>
Kind Regards,
Jeroen.
2012 Oct 04 4:13 PM
hi
it is a combintion of both i think
example 1
<identifier>
<key name="group">Test</key>
</identifier>
example 2
<identifier>
<key name="curvename" ="Curve1"/>
<key name="group">Test</key>
</identifier>
example 3
<identifier>
<key name="curvename" ="Curve1"/>
</identifier>
Every case is possible
I tried:
<identifier>
<tt:group>
<tt:cond frq="1">
<key>
<tt:group>
<tt:cond frq="?">
<tt:attribute name="curvename" value-ref="CURVENAME"/>
</tt:cond>
<tt:cond frq="?">
<tt:attribute name="group" value-ref="GROUP"/>
</tt:cond>
</tt:group>
</key>
</tt:cond>
<tt:cond frq="?">
<key>
<tt:group>
<tt:cond frq="?">
<tt:attribute name="curvename" value-ref="CURVENAME"/>
</tt:cond>
<tt:cond frq="?">
<tt:attribute name="group" value-ref="GROUP"/>
</tt:cond>
</tt:group>
</key>
</tt:cond>
</tt:group>
</identifier>
but in this catch I got the exception CX_ST_MATCH_ELEMENT
Kind regards
Marcus
2012 Oct 04 4:31 PM
Hi,
Are you saying that key is 1..n?
In that case, you'll need a <tt:loop>:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<identifier>
<tt:loop ref="ROOT">
<a>
<tt:cond>
<tt:attribute name="att1" value-ref="a"/>
</tt:cond>
<tt:cond>
<tt:attribute name="att2" value-ref="b"/>
</tt:cond>
<tt:skip/>
</a>
</tt:loop>
</identifier>
</tt:template>
</tt:transform>
If that's not the case, it's maybe easier if you attach a few example XML files to your message (use the advanced editor)
Kind Regards,
Jeroen
2012 Oct 05 7:31 AM
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
<tt:root name="RESPONSE" type="ddic:ZMS_XML_PRICERESULT_SUBJECT"/>
<tt:template>
<response>
<subject>
<identifier>
<key name="category" tt:value-ref=".RESPONSE.CATEGORY"/>
</identifier>
<identifier>
<key>
<tt:group>
<tt:cond data="'curvename'=ref('.RESPONSE.CURVENAME_TXT')">
<tt:attribute name="name">
<tt:value ref=".RESPONSE.CURVENAME_TXT"/>
</tt:attribute>
<tt:value ref=".RESPONSE.CURVENAME"/>
<!-- </key>-->
</tt:cond>
<tt:cond data="'hdbgroup'=ref('.RESPONSE.CURVENAME_TXT')">
<!-- <key>-->
<tt:attribute name="name">
<tt:value ref=".RESPONSE.CURVENAME_TXT"/>
</tt:attribute>
<tt:value ref=".RESPONSE.HDBGROUP"/>
</tt:cond>
</tt:group>
</key>
</identifier>
</subject>
</response>
</tt:template>
</tt:transform>
The structure has only four elements type char 30
CATEGORY
CURVENAME
HDBGROUP
CURVENAME_TXT
2012 Oct 05 9:53 AM
Hi,
Im tot sure what you want to achieve but looking to your examples I think you mixup a few things or making it too difficult.
The structure of the XML is nested, multiple identifiers can exist and each can have multiple keys.
Each key element has only 1 attribute name. This is always the case. So there is no conditional processing needed. It's the values that are changing.
I think it's easier to first parse the XML content in a table having the same structure as the XML.
Then if needed you can transform this table to another structure in your program by looping over the result.
I think with the information you have your question is answered
Kind regards,
Jeroen