Skip to main content
Solved

XML Templater to read a List


laxmi_2590
Contributor
Forum|alt.badge.img+2

Hi Everyone,

 

I have recently started with FME. I have a case where I have to format an XML from a list. 

I am using XMLTemplater Transformer to build a request xml which looks like below

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wnb="http://sample.com.au">
   <soapenv:Header/>
   <soapenv:Body>
      <wnb:fetchNotificationDetails>
         <!--1 or more repetitions:-->
         <notificationNo>121</notificationNo>
         <notificationNo>131</notificationNo>
     <notificationNo>141</notificationNo>
      </wnb:fetchNotificationDetails>
   </soapenv:Body>
</soapenv:Envelope>

 

 

 I am passing some ten notification numbers to a XML templater and they are coming out individually like below 

 

   <soapenv:Header/>
   <soapenv:Body>
      <wnb:fetchNotificationDetails>
         <!--1 or more repetitions:-->
         <notificationNo>301</notificationNo> 
      </wnb:fetchNotificationDetails>
   </soapenv:Body>
</soapenv:Envelope>

 

 <soapenv:Header/>
   <soapenv:Body>
      <wnb:fetchNotificationDetails>
         <!--1 or more repetitions:-->
         <notificationNo>302</notificationNo> 
      </wnb:fetchNotificationDetails>
   </soapenv:Body>
</soapenv:Envelope>

 

I used a listbuilder transformer and then passed it to XMLTemplater .

 

What is the option I should select from the below to read a list to form request XML mentioned below


I want a single output from XML templater which looks like below

 

 <soapenv:Header/>
   <soapenv:Body>
      <wnb:fetchNotificationDetails>
         <!--1 or more repetitions:-->
         <notificationNo>121</notificationNo>
         <notificationNo>131</notificationNo>
     <notificationNo>141</notificationNo>
      </wnb:fetchNotificationDetails>
   </soapenv:Body>
</soapenv:Envelope>

 

Any help would be appreciated. Thanks

 

 

Best answer by s.jager

II would solve this by using a creator for the root element, then inside the root element use process-features to get your list of notification ID’s. So something like this:

where the Root Template Expression is this:

<Body>
  <fetchNotificationDetails>
    {fme:process-features("NOTIFICATION_IDS")}
  </fetchNotificationDetails>
</Body>

And the Sub Template NOTIFICATION_IDS looks like this:

<notificationNo>{fme:get-attribute("NotificationID")}</notificationNo>

When I run this, this gives me the following XML Result:

<?xml version="1.0" encoding="UTF-8"?>
<Body>
  <fetchNotificationDetails>
    <notificationNo>0</notificationNo>
    <notificationNo>1</notificationNo>
    <notificationNo>2</notificationNo>
    <notificationNo>3</notificationNo>
    <notificationNo>4</notificationNo>
    <notificationNo>5</notificationNo>
    <notificationNo>6</notificationNo>
    <notificationNo>7</notificationNo>
    <notificationNo>8</notificationNo>
    <notificationNo>9</notificationNo>
  </fetchNotificationDetails>
</Body>

Which seems to be what you are looking for. Of course my example is a bit simplifed, you’ll need to include the namespaces and stuff, but this should get you going.

 

View original
Did this help you find an answer to your question?

5 replies

s.jager
Influencer
Forum|alt.badge.img+16
  • Influencer
  • Best Answer
  • August 27, 2024

II would solve this by using a creator for the root element, then inside the root element use process-features to get your list of notification ID’s. So something like this:

where the Root Template Expression is this:

<Body>
  <fetchNotificationDetails>
    {fme:process-features("NOTIFICATION_IDS")}
  </fetchNotificationDetails>
</Body>

And the Sub Template NOTIFICATION_IDS looks like this:

<notificationNo>{fme:get-attribute("NotificationID")}</notificationNo>

When I run this, this gives me the following XML Result:

<?xml version="1.0" encoding="UTF-8"?>
<Body>
  <fetchNotificationDetails>
    <notificationNo>0</notificationNo>
    <notificationNo>1</notificationNo>
    <notificationNo>2</notificationNo>
    <notificationNo>3</notificationNo>
    <notificationNo>4</notificationNo>
    <notificationNo>5</notificationNo>
    <notificationNo>6</notificationNo>
    <notificationNo>7</notificationNo>
    <notificationNo>8</notificationNo>
    <notificationNo>9</notificationNo>
  </fetchNotificationDetails>
</Body>

Which seems to be what you are looking for. Of course my example is a bit simplifed, you’ll need to include the namespaces and stuff, but this should get you going.

 


laxmi_2590
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • August 27, 2024

Hi s.jager ,

 

Thanks for your response and that really helped. I am able to send  all the notifications in a single call.

Thanks a lot.

May I ask you another query related to response,  I get a response for the above notification request as below

<notificationDetails>
            <notificationNo>121</notificationNo>
            <notificationStatus>Found</notificationStatus>
            <jobType>SF</jobType>
            <jobDescription>Test</jobDescription>
            <flNumber>110</flNumber>
         </notificationDetails>
         <notificationDetails>
            <notificationNo>131</notificationNo>
            <notificationStatus>Found</notificationStatus>
            <jobType>SF</jobType>
            <jobDescription>Test</jobDescription>
            <flNumber>111</flNumber>
         </notificationDetails>
         <notificationDetails>
            <notificationNo>141</notificationNo>
            <notificationStatus>Not Found</notificationStatus>
            <jobType></jobType>
            <jobDescription></jobDescription>
            <flNumber></flNumber>
         </notificationDetails>

 

Is there anyway that I can get the output in to rows like below

 

NotificationNo notificationStatus jobType jobDescription flNumber
121 Found SF Test 110


Is there a transformer I can use to do that ?
Thanks again for your help. :)


s.jager
Influencer
Forum|alt.badge.img+16
  • Influencer
  • August 28, 2024

I’m not sure what you mean by 

get the output in to rows

You wanted xml, that’s what you get. And you already have the features with the attributes, so that is already in sort of a tabular format. Do you want to see it in the Data Explorer? Then just add an Inspector right in front of the XMLTemplater. Or do you also want an excel or an html table as secondary output?


laxmi_2590
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • August 29, 2024

Hi s.jager,

 

Thanks for your response.

I want to extract the attributes of the response xml for further processing.

 

If below is my response xml, 

<notificationDetails>
            <notificationNo>121</notificationNo>
            <notificationStatus>Found</notificationStatus>
            <jobType>SF</jobType>
            <jobDescription>Test</jobDescription>
            <flNumber>110</flNumber>
         </notificationDetails>
         <notificationDetails>
            <notificationNo>131</notificationNo>
            <notificationStatus>Found</notificationStatus>
            <jobType>SF</jobType>
            <jobDescription>Test</jobDescription>
            <flNumber>111</flNumber>
         </notificationDetails>
         <notificationDetails>
            <notificationNo>141</notificationNo>
            <notificationStatus>Not Found</notificationStatus>
            <jobType></jobType>
            <jobDescription></jobDescription>
            <flNumber></flNumber>
         </notificationDetails>

 

 I have to take each one of these notification IDS and respective job type, job desc etc to query another table and get some other information. 
 

NotificationNo notificationStatus jobType jobDescription flNumber

121

122

Found

Not Found

SF

SK

Test
Testq

110

112

 

I tried using AttributeExploder to extract the attribute values. But that is not giving me the expected result,

I hope I made it a little clear now. 


s.jager
Influencer
Forum|alt.badge.img+16
  • Influencer
  • August 29, 2024

Ah, that makes more sense, thank you for clearing that up.

To create features from the response xml, the XMLFragmenter is probably your best option.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings