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
## 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.
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<root> | |
<test xmlns="www.testnamespace1.com"> | |
<some_content1>text some_content1 testnamespace1</some_content1> | |
<some_content2> | |
<another_content>text another_content</another_content> | |
</some_content2> | |
</test> | |
<test xmlns="www.testnamespace2.com"> | |
<some_content1>text some_content1 testnamespace2</some_content1> | |
<some_content2> | |
</some_content2></test> | |
</root> |
XPath
//*[local-name()='some_content1']/text()
Result in Sterling
text some_content1 testnamespace1text some_content1 testnamespace2
Result in http://www.xpathtester.com/xpath
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<process name="test_xml_namespace"> | |
<sequence name="MainStart"> | |
<assign from="DocToDOM(PrimaryDocument)" to="."> | |
<assign from="//*[local-name()='some_content1']/text()" to="result1"> | |
<assign from="DocToDOM(PrimaryDocument)" to="."> | |
<assign from="(//*[local-name()='some_content1'])[1]/text()" to="result1"> | |
<assign from="//*[local-name()='some_content1' and namespace-uri()='www.testnamespace1.com']/text()" to="result2"> | |
<assign from="//*[local-name()='some_content2' and namespace-uri()='www.testnamespace1.com']/*[local-name()='another_content' and namespace-uri()='www.testnamespace1.com']/text()" to="result3"> | |
</assign> | |
</assign> | |
</assign></assign></assign></assign></sequence> | |
</process> |
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<root xmlns:test1="www.testnamespace1.com" xmlns:test2="www.testnamespace2.com"> | |
<test1:test> | |
<test1:some_content1>text some_content1 testnamespace1</test1:some_content1> | |
<test1:some_content2> | |
<test1:another_content>text another_content</test1:another_content> | |
</test1:some_content2> | |
</test1:test> | |
<test2:test> | |
<test2:some_content1>text some_content1 testnamespace2</test2:some_content1> | |
<test2:some_content2> | |
</test2:some_content2></test2:test> | |
</root> |
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.
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<process name="test_xml_namespace"> | |
<sequence name="MainStart"> | |
<assign from="DocToDOM(PrimaryDocument)" to="."></assign> | |
<assign from="root/test2:test/test2:some_content1/text()" to="result1"></assign> | |
<assign from="DocToDOM(PrimaryDocument)" to="."></assign> | |
<assign from="root/test1:test/test1:some_content1/text()" to="result2"></assign> | |
<assign to="result3/test1:sometag">This includes the namespace defined on Sterling</assign> | |
</sequence> | |
</process> |
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