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.

<Messages
    xmlns="http://www.connectplaza.com/generic-consignment"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          version="1.00"
          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:

//*[local-name()='Message']

 

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:

/*[local-name()='root']/*[local-name()='element1']/ 

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">
	<soapenv:Body>
		<notifications xmlns="http://soap.sforce.com/2005/09/outbound">
			<OrganizationId>BLADIBLA</OrganizationId>
			<ActionId>xxxxxxxxxxxxxxx</ActionId>
			<SessionId xsi:nil="true"/>
			<EnterpriseUrl>https://connecttest--esbox.sandbox.my.salesforce.com/services/Soap/c/57.0/00X8F0000000PAO</EnterpriseUrl>
			<PartnerUrl>https://connecttest--esbox.sandbox.my.salesforce.com/services/Soap/u/57.0/00X8F0000000PAO</PartnerUrl>
			<Notification>
				<Id>0239A0000045GahOKI</Id>
				<sObject xsi:type="sf:Customer_Catalog__c"  xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
					<sf:Id>b3H7K456787HLASEW2</sf:Id>
					<sf:Account_Name__c>b3H7K456787HLASEW2</sf:Account_Name__c>
					<sf:CatalogName__c>test CP</sf:CatalogName__c>
					<sf:Name>HJ-5298</sf:Name>
				</sObject>
			</Notification>
		</notifications>
	</soapenv:Body>
</soapenv:Envelope>

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.