XmlQuery

Metreos.Native.Xml.XmlQuery

Summary

XmlQuery will query an XML document with XPath.

Usage

The XmlQuery action will return both a XmlNodeList and a System.Collections.Specialized.StringCollection, with the results of the XPath expression. The XmlNodeList will return complex types that can be further processed in CustomCode. The StringCollection will return just the textual values of the matching elements.

The use of XmlQuery requires understanding of XML and XPath. The following is an example to illustrate how these technologies interact in the context of this action:

Example 22.1. Sample XML Document supplied as the Xml action parameter in XmlQuery


<?xml version="1.0" ?>
<a>
 <b>
   <c myattr="1" />
 </b>
</a>

  

Example 22.2. XPath expression supplied as the Query action parameter in XmlQuery


//@myattr

  

Example 22.3. Parsing the ValueList and XmlNodeList result parameters of XmlQuery


public static string Execute(System.Xml.XmlNodeList nodes, StringCollection values, LogWriter log)
{
 // The result of '//@myattr' should be just one node for the sample XML document.
 // The two traces below will output the following:
 // 'XML Node List Data: 1 myattr'
 // 'StringCollection Data: 1'

 log.Write(TraceLevel.Info, "XML Node List Data: {0} {1}", nodes[0].Value, nodes[0].Name);
 log.Write(TraceLevel.Info, "StringCollection Data: {0}", values[0]);

 return "Success";
}

  

Remarks

None.

Action Parameters
Parameter Name.NET TypeDefaultDescription
Xml *System.StringThe XML document to use the XPath expression against specified by the Query action parameter.
Query *System.StringThe XPath expression to use on the content specified by the Xml action parameter.
Result Data
Parameter Name.NET TypeDescription
XmlNodeListMetreos.Types.Xml.XmlNodeListThe list of XML nodes the XPath expression found. This value should be saved to the XmlNodeList type.
ValueListMetreos.Types.StringCollectionThe textual values of the list of XML nodes the XPath expression found.

Branch Conditions 

Success

No description.

Failure

No description.