Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

XML Transformation - XML matching error

aaron_morden2
Contributor
0 Likes
467

Hello all,

I am having problems with the simple transformation I wrote. Below is a small part of my transformation:


<?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="SDNENTRY" type="ddic:ZOFAC_SDN_ENTRY"/>
  <tt:root name="PUBLISHINFORMATION" type="ddic:ZOFAC_PUBLISHINFO_STR"/>
  <tt:template>
    <sdnList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/sdnList.xsd">
      <publshInformation>
        <Publish_Date tt:value-ref="PUBLISHINFORMATION.PUBLISH_DATE"/>
        <Record_Count tt:value-ref="PUBLISHINFORMATION.RECORD_COUNT"/>
      </publshInformation>
      <tt:loop ref=".SDNENTRY">
        <sdnEntry>
          <uid tt:value-ref="SDN_ID"/>
          <firstName tt:value-ref="FIRST_NAME"/>
          <lastName tt:value-ref="LAST_NAME"/>
          <title tt:value-ref="TITLE"/>
          <sdnType tt:value-ref="SDN_TYPE"/>
        </sdnEntry>

The problem that I am having is that certain elements of the XML file are optional and will not be supplied. XML Example:


<sdnEntry>
  <uid>737</uid> 
  <firstName>John</firstName>
  <lastName>Doe</lastName> 
  <sdnType>Individual</sdnType> 
</sdnEntry>

In the above example, title is not given. If I run my program I get an XML Matching Error because it expected title, but read sdnType.

How do I write my transformation so that if the element is not supplied it will just move on to the next element?

Thank you very much. Let me know if more info is needed!

1 REPLY 1
Read only

aaron_morden2
Contributor
0 Likes
367

Problem solved.

Used a <tt:cond check> in my tranformation. See below:


<?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="SDNENTRY" type="ddic:ZOFAC_SDN_ENTRY"/>
  <tt:root name="PUBLISHINFORMATION" type="ddic:ZOFAC_PUBLISHINFO_STR"/>
  <tt:template>
    <sdnList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/sdnList.xsd">
      <publshInformation>
        <Publish_Date tt:value-ref="PUBLISHINFORMATION.PUBLISH_DATE"/>
        <Record_Count tt:value-ref="PUBLISHINFORMATION.RECORD_COUNT"/>
      </publshInformation>
      <tt:loop ref=".SDNENTRY">
        <sdnEntry>
          <uid tt:value-ref="SDN_ID"/>
          <firstName tt:value-ref="FIRST_NAME"/>
          <lastName tt:value-ref="LAST_NAME"/>
           <tt:cond check="not-initial(TITLE)">
            <title tt:value-ref="TITLE"/>
          </tt:cond>
          <sdnType tt:value-ref="SDN_TYPE"/>
        </sdnEntry>

Thank You.