<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://www.xlayer.co.za/forum/extern.php?action=feed&amp;tid=54&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[SXI Forum / How to collect an Attribute from an XML (esp. Web Service Response)]]></title>
		<link>https://www.xlayer.co.za/forum/viewtopic.php?id=54</link>
		<description><![CDATA[The most recent posts in How to collect an Attribute from an XML (esp. Web Service Response).]]></description>
		<lastBuildDate>Thu, 22 Nov 2018 05:40:54 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[How to collect an Attribute from an XML (esp. Web Service Response)]]></title>
			<link>https://www.xlayer.co.za/forum/viewtopic.php?pid=74#p74</link>
			<description><![CDATA[<p>OK ... so there is no simple way to do this currently.</p><p>I had to get the &quot;status&quot; attribute from the following xml:</p><div class="codebox"><pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;S:Envelope xmlns:S=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
  &lt;S:Body&gt;
    &lt;ns2:processTransactionResponse xmlns:ns2=&quot;http://soap.sxi.co.za/&quot;&gt;
      &lt;SXIReturn status=&quot;FAILED&quot;&gt;
        &lt;message&gt;Failed to create XML file.&lt;/message&gt;
        &lt;transID&gt;1513606805687&lt;/transID&gt;
      &lt;/SXIReturn&gt;
    &lt;/ns2:processTransactionResponse&gt;
  &lt;/S:Body&gt;
&lt;/S:Envelope&gt;&lt;/code&gt;&lt;/pre&gt;</code></pre></div><p>however when I used the following XPath:</p><div class="codebox"><pre><code>//*[local-name()=&#039;SXIReturn&#039;]/@status</code></pre></div><p>only the word status was returned .. however it worked in Oxygen (although it did return the full attribute &gt;status=&quot;FAILED&quot;&lt;</p><p>The only way I have found so far to fetch an attribute is to address it via a stylesheet using an ApplyStyleSheetToMemoryContents mapping in XLayer using a simple stylesheet that looks as follows:</p><div class="codebox"><pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;1.0&quot;&gt;
    &lt;xsl:output method=&quot;xml&quot; indent=&quot;yes&quot; omit-xml-declaration=&quot;no&quot;/&gt;
    &lt;xsl:variable name=&quot;status&quot; select=&quot;//*[local-name()=&#039;SXIReturn&#039;][last()]/@status&quot;/&gt;
    &lt;xsl:template match=&quot;@*|node()&quot;&gt;
        &lt;xsl:copy&gt;
            &lt;xsl:apply-templates /&gt;
        &lt;/xsl:copy&gt;
        &lt;xsl:if test=&quot;@status&quot;&gt;
           &lt;xsl:apply-templates select=&quot;@status&quot; /&gt;
       &lt;/xsl:if&gt;
    &lt;/xsl:template&gt;    
    &lt;xsl:template match=&quot;@status&quot;&gt;
        &lt;SXIReturnStatus&gt;&lt;xsl:value-of select=&quot;$status&quot; /&gt;&lt;/SXIReturnStatus&gt;
    &lt;/xsl:template&gt;    
&lt;/xsl:stylesheet&gt;&lt;/code&gt;&lt;/pre&gt;</code></pre></div><p>This copies all the xml but ALSO create a new xml element called &quot;SXIReturnStatus&quot; and adds the value of the status attribute to it.</p><p>This way I can run a &quot;MemoryDataManipulation&quot; mapping to see if the status was SUCCESS or FAILURE using a condition as follows:</p><div class="codebox"><pre><code>&lt;MemoryDataManipulation dataDefinition=&quot;GetSOAPStatus&quot;&gt;
     &lt;Conditions&gt;
         &lt;Condition&gt;
             &lt;When field=&quot;//*[local-name()=&#039;MySoapStatus&#039;]&quot; operator=&quot;Matches&quot; value=&quot;FAILED&quot;&gt;
                 &lt;LogComment Comment=&quot;==== FAILED FAILED FAILED =====&quot;/&gt;
             &lt;/When&gt;
         &lt;/Condition&gt;
     &lt;/Conditions&gt;
 &lt;/MemoryDataManipulation&gt;
 </code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (SeanR)]]></author>
			<pubDate>Thu, 22 Nov 2018 05:40:54 +0000</pubDate>
			<guid>https://www.xlayer.co.za/forum/viewtopic.php?pid=74#p74</guid>
		</item>
	</channel>
</rss>
