XPATH Expressions with namespaces

XML file with namespaces

If your XML file of messagepart has namespaces, you cannot use the above syntax for the XPATH Splitter. You have to use a specific syntax to deal with this.

You can detect namespaces whan the XMLNS property is used in the tag.

          xsi:schemaLocation="http://www.connectplaza.cm.com/generic-consignment file:///A:/Projects/Order/Schemas/Customer/CP_Consumption.xsd">

If you want alle message from messages, you normally type: /Messages/* or /Message/message. But in this case you need the localname variant:



If you have an XML document with namespaces you have to declare them beforehand. That may be possible in an online parser , in our Agent it is not possible because the parser (which executes the xpaths) is already loaded. The result is that you can't do normal expressions because the parser can't find the elements (since they are loaded in a namespace).

The solution is local-name() syntax. This indicates in the expression that you are not interested in the namespace in which the element is located, but in the element itself based on its local name. Hence the expression:


Example 2

Another example. See the XML file below:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
		<notifications xmlns="http://soap.sforce.com/2005/09/outbound">
			<SessionId xsi:nil="true"/>
				<sObject xsi:type="sf:Customer_Catalog__c"  xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
					<sf:CatalogName__c>test CP</sf:CatalogName__c>

If you, for instance, want to test the value of xsi:type="sf:Customer_Catalog__c" you have to setup the following xpath expression. This will return a boolean.

//*[local-name()='sObject']/@*[local-name()='type'] = 'sf:Customer_Catalog__c'

Notice the use of [local-name()=...] twice in this expression.