quinta-feira, 6 de março de 2014

Sterling B2B Integrator XPath and namespace

The are two ways to handle namespaces on Sterling, using a registered prefix or specifying on the XPath the namespace URI.

To work with default namespace there is no other option rather then using XPath URI.

If the namespace uses prefix using XPath URI can be quite tricky for complex queries so you might think about just registering the namespace to avoid extra complexity on the XPath queries. The procedure to register a namespace is described bellow.

Having the following code has an XML


XPath

//*[local-name()='some_content1']/text()

Result in Sterling

text some_content1 testnamespace1text some_content1 testnamespace2

Result in http://www.xpathtester.com/xpath
text some_content1 testnamespace1 text some_content1 testnamespace2

XPath

(//*[local-name()='some_content1'])[1]/text()

Result

text some_content1 testnamespace1

XPath

//*[local-name()='some_content1' and namespace-uri()='www.testnamespace1.com']/text()

Result

text some_content1 testnamespace1

XPath

//*[local-name()='some_content2' and namespace-uri()='www.testnamespace1.com']/*[local-name()='another_content' and namespace-uri()='www.testnamespace1.com']/text()

Result

text another_content

BPML of test_xml_namespace


Results on Process Data



  • To update you're namespace on Sterling you need to edit the namespace.properties file and add a new entry as following:


## PROPERTY_START
## PROPERTY_NAME: test1
## PROPERTY_TYPE: String
## PROPERTY_DESCRIPTION
##
test1 = www.testnamespace1.com
## PROPERTY_END

## PROPERTY_START
## PROPERTY_NAME: test2
## PROPERTY_TYPE: String
## PROPERTY_DESCRIPTION
##
test2 = www.testnamespace2.com
## PROPERTY_END

And run ./opscmd.sh -cREFRESHNAMESPACES -nnode1
There might be some errors but normally it should work.

Testing against an XML with prefixes


XPath

root/test2:test/test2:some_content1/text()

Result

text some_content1 testnamespace2

XPath

root/test1:test/test1:some_content1/text()

Result

text some_content1 testnamespace1

BPML of test_xml_namespace updated


Results on Process Data

Bottom line is to register namespace while dealing with prefix otherwise stick to XPath local names and URIs.

Sem comentários:

Enviar um comentário