Answers.Body: <p>Still not quite sure I understand the problem completely, but here are some ideas to get you started. Your workflow requires three steps:</p>
  <ol>
  <li>Fetch the XML data from the external API.</li>
  <li>Parse the XML (the SOAP namespace may require some attention) into a usable format.</li>
  <li>Filter and display the parsed data in your template.</li>
  </ol>
  <p>I assume your existing code is based on <a href="https://docs.craftcms.com/feed-me/v4/feature-tour/using-in-your-templates.html" rel="nofollow noreferrer">this example for using feeds in your template</a>? In this case, the feed me plugin does steps 1 &amp; 2 for you, at least to a degree. The documentation doesn't actually mention if the plugin is capable of handling SOAP documents, but since you mentioned that part is working, I'll assume it does. If it doesn't, you can also bypass the plugin and use <a href="https://www.php.net/manual/en/class.soapclient.php" rel="nofollow noreferrer">PHP's SoapClient</a> directly, though that might be a bit tedious.</p>
  <p>With Feed Me, you have to figure out what the <a href="https://docs.craftcms.com/feed-me/v4/feature-tour/primary-element.html" rel="nofollow noreferrer">primary element</a> in the XML result is. You will need to make sure the document has a consistent format at least to that degree. Based on your example, the primary element is probably the <code>student</code> node. So the code would look something like this:</p>
  <pre><code>{% set params = {
      url: 'http://path.to/feed/',
      type: 'xml',
      element: 'student',
      cache: 60,
  } %}
  
  {% set feed = craft.feedme.feed(params) %}
  </code></pre>
  <p>Now all that remains is to loop through the results and display the data. If you're not sure about the fields in the XML documents, you can use Twig to check if specific fields are defined and display them:</p>
  <pre><code>{% for student in feed %}
      {% if student.studentAttributes is defined %}
          Employee ID: {{ student.studentAttributes.emplid ?? 'No employee ID' }}
          PVI: {{ student.studentAttributes.pvi ?? 'Not found' }}
      {% endif %}
      {# ... #}
  {% endfor %}
  </code></pre>
  <p>Hopefully this helps. If you're having trouble with a specific step (displaying fields conditionally, parsing the data with Feed Me, etc) please post the code you're having trouble with, this will make it easier to find what's going wrong.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-08T14:29:34.400Z
Answers.Text: thanks, this is very helpful. It seems part of my issue was a very elementary mistake on my part, not related to the feed itself. A related question about accessing the feed, in order to generate this specific SOAP feed, I have to pass it a SOAP-based query, also in XML. How would one do that in Craft?
Answers.UserDisplayName: 4midori
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-08T14:46:28.530Z
Answers.Text: @4midori Not sure I understand. Where exactly is this feed coming from, an external API that requires SOAP? In this question, I don't think Craft provides any utilities for SOAP APIs, it's a pretty dated standard after all ... I thought your question indicated that Feed Me already takes care of accessing the feed, or was that a misunderstanding? Anyway, if Feed Me doesn't do this, you'll probably need to do that manually using the [SoapClient](https://www.php.net/manual/en/class.soapclient.php) class or an external library.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-08T15:46:39.860Z
Answers.Text: That is correct, the feed comes from an external API that requires SOAP. Right now I am using Feed Me on a sample XML document. Basically, I saved the feed's results and am hitting that in that of hitting the feed directly. I don't believe Feed Me can send a SOAP request.
Answers.UserDisplayName: 4midori
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-09T07:29:49.273Z
Answers.Text: @4midori Ok, I see, so Feed Me won't really help you there. I'm not that familiar with SOAP, but the [laminas (Zend) library for SOAP](https://docs.laminas.dev/laminas-soap/client/) looks solid, maybe you could use that? Or maybe just the barebones [PHP SOAP module](https://www.php.net/manual/en/book.soap.php), there are some [good comments here](https://www.php.net/manual/en/soapclient.soapcall.php) which explain how to send SOAP calls with the SoapClient class.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-08T11:14:42.277Z
Answers.LastActivityDate: 2021-09-08T11:14:42.277Z
Answers.UserDisplayName: MoritzLost
Body: <p>I need to display some of the elements within an XML feed (SOAP) as HTML. I don't want to store it in the database, but rather, just hit the API each time the data is needed.</p>
  <p>I have been able to do this in a rudimentary way with the Feed Me plug-in, but I can tell that, given how the data is nested, and that I don't need all of it, I need a more robust approach. Here is the start of how the data looks. This file goes on for quite a while.</p>
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
   &lt;soapenv:Body&gt;
    &lt;ns2:GetStudentsResponse xmlns:ns2=&quot;http://whatever.com&quot; xmlns=&quot;http://whatever.com&quot;&gt;
       &lt;student&gt;
          &lt;personAttributes&gt;
             &lt;emplid&gt;394837&lt;/emplid&gt;
             &lt;pvi&gt;AB94309&lt;/pvi&gt;
             &lt;name&gt;
                &lt;first&gt;Dorothy&lt;/first&gt;
                &lt;middle&gt;X&lt;/middle&gt;
                &lt;last&gt;Liu&lt;/last&gt;
             &lt;/name&gt;
  
             etc...
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-07T16:07:04.587Z
Comments.Text: Just to clarify – you're getting data from an external API as XML and want to output it on a page as HTML? What part of that workflow is/isn't working, what are you having trouble with? What are you using the Feed Me plugin for?
Comments.UserDisplayName: MoritzLost
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-07T17:52:30.663Z
Comments.Text: That is correct. Given that the data is nested many levels deep, and I need to get some of it selectively, I'm not sure how to do that. For example, it's not clear to me how to a) check whether a node in the Twig array exists, and b) display it conditionally. BTW, if I use {{ dd(myvar) }} I can see the array.
  
  I'm also wondering whether using Feed Me will give me enough flexibility, or if I need to leverage a different tool.
Comments.UserDisplayName: 4midori
Tags: <plugins><plugin-feedme><xml>
Title: Converting nested XML (SOAP) feed to HTML
ThreadText: # Converting nested XML (SOAP) feed to HTML
  
  (Asked by: username_0 on 2021-09-03)
  
  I need to display some of the elements within an XML feed (SOAP) as HTML. I don't want to store it in the database, but rather, just hit the API each time the data is needed.
  
  I have been able to do this in a rudimentary way with the Feed Me plug-in, but I can tell that, given how the data is nested, and that I don't need all of it, I need a more robust approach. Here is the start of how the data looks. This file goes on for quite a while.
  
  ```
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
    <ns2:GetStudentsResponse xmlns:ns2="http://whatever.com" xmlns="http://whatever.com">
       <student>
          <personAttributes>
             <emplid>394837</emplid>
             <pvi>AB94309</pvi>
             <name>
                <first>Dorothy</first>
                <middle>X</middle>
                <last>Liu</last>
             </name>
  
             etc...
  
  ```
  
  **Tags:** plugins, plugin-feedme, xml
  
  > **Comments:**
  > **username_1**: Just to clarify – you're getting data from an external API as XML and want to output it on a page as HTML? What part of that workflow is/isn't working, what are you having trouble with? What are you using the Feed Me plugin for?  
  > **username_0**: That is correct. Given that the data is nested many levels deep, and I need to get some of it selectively, I'm not sure how to do that. For example, it's not clear to me how to a) check whether a node in the Twig array exists, and b) display it conditionally. BTW, if I use {{ dd(myvar) }} I can see the array.  I'm also wondering whether using Feed Me will give me enough flexibility, or if I need to leverage a different tool.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-09-08. Score: 1
  
  Still not quite sure I understand the problem completely, but here are some ideas to get you started. Your workflow requires three steps:
  
  1. Fetch the XML data from the external API.
  2. Parse the XML (the SOAP namespace may require some attention) into a usable format.
  3. Filter and display the parsed data in your template.
  
  I assume your existing code is based on [this example for using feeds in your template](https://docs.craftcms.com/feed-me/v4/feature-tour/using-in-your-templates.html)? In this case, the feed me plugin does steps 1 & 2 for you, at least to a degree. The documentation doesn't actually mention if the plugin is capable of handling SOAP documents, but since you mentioned that part is working, I'll assume it does. If it doesn't, you can also bypass the plugin and use [PHP's SoapClient](https://www.php.net/manual/en/class.soapclient.php) directly, though that might be a bit tedious.
  
  With Feed Me, you have to figure out what the [primary element](https://docs.craftcms.com/feed-me/v4/feature-tour/primary-element.html) in the XML result is. You will need to make sure the document has a consistent format at least to that degree. Based on your example, the primary element is probably the `student` node. So the code would look something like this:
  
  ```
  {% set params = {
      url: 'http://path.to/feed/',
      type: 'xml',
      element: 'student',
      cache: 60,
  } %}
  
  {% set feed = craft.feedme.feed(params) %}
  
  ```
  
  Now all that remains is to loop through the results and display the data. If you're not sure about the fields in the XML documents, you can use Twig to check if specific fields are defined and display them:
  
  ```
  {% for student in feed %}
      {% if student.studentAttributes is defined %}
          Employee ID: {{ student.studentAttributes.emplid ?? 'No employee ID' }}
          PVI: {{ student.studentAttributes.pvi ?? 'Not found' }}
      {% endif %}
      {# ... #}
  {% endfor %}
  
  ```
  
  Hopefully this helps. If you're having trouble with a specific step (displaying fields conditionally, parsing the data with Feed Me, etc) please post the code you're having trouble with, this will make it easier to find what's going wrong.
  
  > **Comments:**
  > **username_0**: thanks, this is very helpful. It seems part of my issue was a very elementary mistake on my part, not related to the feed itself. A related question about accessing the feed, in order to generate this specific SOAP feed, I have to pass it a SOAP-based query, also in XML. How would one do that in Craft?  
  > **username_1**: @username_0 Not sure I understand. Where exactly is this feed coming from, an external API that requires SOAP? In this question, I don't think Craft provides any utilities for SOAP APIs, it's a pretty dated standard after all ... I thought your question indicated that Feed Me already takes care of accessing the feed, or was that a misunderstanding? Anyway, if Feed Me doesn't do this, you'll probably need to do that manually using the [SoapClient](https://www.php.net/manual/en/class.soapclient.php) class or an external library.  
  > **username_0**: That is correct, the feed comes from an external API that requires SOAP. Right now I am using Feed Me on a sample XML document. Basically, I saved the feed's results and am hitting that in that of hitting the feed directly. I don't believe Feed Me can send a SOAP request.  
  > **username_1**: @username_0 Ok, I see, so Feed Me won't really help you there. I'm not that familiar with SOAP, but the [laminas (Zend) library for SOAP](https://docs.laminas.dev/laminas-soap/client/) looks solid, maybe you could use that? Or maybe just the barebones [PHP SOAP module](https://www.php.net/manual/en/book.soap.php), there are some [good comments here](https://www.php.net/manual/en/soapclient.soapcall.php) which explain how to send SOAP calls with the SoapClient class.  
  
  ---
  
  