Guide Overview
Summary:
Use XPath to drill into XML response bodies so you can identify acceptance/rejection outcomes and extract rejection reasons.
Learning Objectives:
- Understand how XPath traverses an XML document using
/between parent and child nodes. - Configure mappings that identify a lead as accepted based on an XML response body.
- Extract a rejection reason from an XML response body (including why
"/text()"is used in the Reason Path). - Handle repeating nodes (arrays), node attributes, and namespaced (SOAP-style) XML.
- Override response parsing when the response
Content-Typeheader is incorrect.
Quick Start Workflow
- Get a sample XML response body (accepted and rejected examples are below).
- Determine the XPath to the outcome node (where the response indicates accepted/rejected).
- Configure your outcome mapping using the appropriate Outcome Search Term and Outcome Search Path.
-
Configure the rejection reason mapping using a Reason Path (typically with
"/text()"). - Handle advanced cases (repeating nodes, attributes, namespaces) and use Response Content Type Override if parsing fails.
Step‑by‑Step Instructions
Step 1. Understand XML and XPath paths
- Goal: Know how to express “where the data is” in the XML as a single XPath string.
- Context: XML is hierarchically structured and human-readable. XPath drills into the XML from the outermost (root) node down to the node you want to extract. To learn more about XML, see: https://www.tutorialspoint.com/xml/
Instructions:
- Start at the outermost (root) level of the XML document.
- Drill down by specifying deeper node names separated by
/between parent and child nodes. - Continue until you reach the node you need to extract.
Expected Result: You can write an XPath that targets a specific node in your XML response.
Step 2. Identify an accepted response
- Goal: Recognize an accepted lead using an XML response body.
- Context: If the response body for an accepted lead looks like the example below, your mapping can identify the lead as accepted.
Instructions:
- Use this example accepted response body:
<result>accepted</result> <errors /> - Configure your mapping so the value
acceptedin theresultnode is used to identify acceptance.
Expected Result: Responses containing the accepted value at the mapped path are identified as accepted.
Step 3. Extract a rejection reason
- Goal: Extract the rejection reason text from a rejected response body.
- Context: A rejected response can contain an error node with a human-readable rejection reason.
Instructions:
- Use this example rejection response body:
<response> <result>rejected</result> <errors> <error>Quota filled for red cars</error> </errors> </response> - Configure the mapping to extract the error text as the rejection reason.
- In the Reason Path, use
"/text()"as a capture group so the mapping extracts the tag’s value (rather than only searching for a match).
Expected Result: The mapping extracts Quota filled for red cars as the rejection reason.
Step 4. Handle repeating nodes (arrays)
- Goal: Handle XML where multiple identically-named nodes appear under a parent node.
- Context: LeadConduit automatically attempts to parse repeating child nodes as arrays.
Instructions:
- Use this example response with repeating
<error>nodes:<response> <result>rejected</result> <errors> <error>Quota filled for red cars</error> <error>Must be older than 18 years</error> </errors> </response> - With the same mappings used above, capture both errors.
- Note that repeating nodes are captured as an array of fields, indexed by integer values starting at 0 (0 = first, 1 = second, etc.).
- If you want to ignore the first error node and capture the second, add a (1-based) position index to the node name in your reason path.
Expected Result: Both errors are captured as an array, and you can select a specific error by position index when needed.
Step 5. Match or capture node attributes
- Goal: Extract values stored in node attributes (key=value pairs in an opening tag).
-
Context: Some responses store the outcome (or other data) as an attribute—for example, an
outcomeattribute on theresultnode.
Instructions:
- Identify whether the value you need is stored as an attribute rather than a child node.
- Use
@to indicate that an XPath term is an attribute (not a child node) of the node just preceding it.
Expected Result: Your mapping can read values stored in XML attributes.
Step 6. Parse namespaced (SOAP-style) XML
-
Goal: Make XPath work on namespaced XML where node names include prefixes (e.g.,
soap:). -
Context: Most XPath parsers (including LeadConduit’s) don’t deal gracefully with namespacing. Namespaced XML often includes attributes that attach namespace names to node names using a colon (e.g.,
soap:Envelope). The example in the source is a SOAP variant.
Instructions:
- To ignore namespaces in your mapping, use this pattern:
/*[name()='nodename'] instead of /nodename - Example: to match the
StatusCodetag as a success response, use:*[name()='soap:Envelope']/*[name()='soap:Body']/*[name()='CreateResponse']/*[name()='Results']/*[name()='StatusCode']
Expected Result: Your XPath mapping can traverse namespaced tags and correctly match/extract the node values you need.
Step 7. Override the response Content-Type when parsing fails
-
Goal: Fix parsing issues caused by an incorrect response
Content-Typeheader. -
Context: If properly-configured parsing is not working, the response
Content-Typeheader may not have been set correctly by the recipient system.
Instructions:
- If parsing fails despite correct mappings, check the response
Content-Typeheader. - Set the desired Content-Type in the Response Content Type Override mapping.
- Common XML Content-Types include:
application/soap+xml; charset=utf-8text/htmlapplication/xml
Expected Result: The response body is parsed using the override type, enabling your XPath mappings to work.
Validate Your Setup
- Use the online XPath expression tester to confirm your XPath expressions match the nodes you intend to target: http://codebeautify.org/Xpath-Tester
- Validate an accepted response using the sample:
<result>accepted</result> <errors /> - Validate a rejected response and confirm the reason extraction (including
"/text()") using the sample:<response> <result>rejected</result> <errors> <error>Quota filled for red cars</error> </errors> </response> - If your XML includes repeating nodes, confirm you receive an array (indexed starting at 0) and that a (1-based) position index selects the specific node you want.
- If parsing still fails, set Response Content Type Override to one of the common XML Content-Types listed above.
Troubleshooting
| Symptom / Error Message | Likely Cause | Resolution |
|---|---|---|
| Properly-configured parsing is not working | Response Content-Type header is incorrect |
Set the desired Content-Type in the Response Content Type Override mapping (examples: application/soap+xml; charset=utf-8, text/html, application/xml). |
| Rejection reason is not extracted from an XML tag | Reason Path is searching but not capturing the tag’s value | Use "/text()" as a capture group in the Reason Path. |
Multiple <error> nodes are returned and you only want one |
Repeating nodes are treated as an array | Add a (1-based) position index to the node name in your reason path to select the specific error node. |
| XPath fails on SOAP/namespaced XML | Namespaces are not handled gracefully by most XPath parsers | Use /*[name()='nodename'] (and the full name()-based path pattern) to ignore namespaces. |
| XPath isn’t reading an attribute value | The XPath is treating an attribute like a child node | Use @ to indicate the value is an attribute of the preceding node. |
Frequently Asked Questions (FAQ)
Why do Reason Path mappings use "/text()"?
Because Reason Path mappings extract the XML tag’s value and incorporate it into the flow as appended data; outcome mappings typically only search for a match in the response.
How does LeadConduit handle repeating nodes?
It automatically attempts to parse repeating, identically-named child nodes as arrays, indexed by integer values starting at 0.
How do I ignore namespaces in XPath mappings?
Use /*[name()='nodename'] instead of /nodename, and apply that pattern throughout the path (see the example path ending in StatusCode).
Where can I learn more about XPath?
Tutorial: https://www.tutorialspoint.com/xpath/index.htm
Glossary
| Term | Definition |
|---|---|
| XML | A hierarchically structured, human-readable format for representing data. |
| XPath | A shorthand technique for drilling into an XML document to extract the contents of a particular node. |
| Node | An XML element/tag in the document hierarchy. |
| Repeating nodes | Identically-named child nodes under the same parent that are parsed as an array. |
| Attribute | A key=value pair within a node’s opening tag. |
| Namespace | A prefix attached to node names using a colon (e.g., soap:Envelope) to qualify node names. |
| SOAP | A variant of XML referenced in the source as an example of namespaced XML. |
| Content-Type | The HTTP header indicating how a response body should be parsed. |
| Response Content Type Override | A mapping used to force parsing as a specified Content-Type when the response header is incorrect. |
- xpath-namespace.jpg100 KB
- xpath-accepted.png300 KB
- xpath-rejection.png100 KB
- xpath-attribute.png600 KB
- xpath-position.png200 KB
- xpath-contenttype.png200 KB
Comments
0 comments
Please sign in to leave a comment.