XPath Expressions in XML – Part I
by Nitin JainThis post has a broad focus, not just Siebel CRM. I have briefly alluded to the XML structures in EAI in some of my previous posts:
A meeting with Siebel EAI
FINS Industry XML Query Service
One of the interesting things that came out of the feedback was parsing the XML and the XPath expressions. This is exactly what I will be covering in my blog post today.
The XPath defines the path, or the way that you parse/read/traverse through an XML. The concept is generic in nature. However, Siebel in itself has some limitations in the way that it handles these expressions. I will try to cover both these scenarios here. I will take the following small XML Snippet as an example for better understanding of the same. One of the best ways to understanding this is to refer this structure of the XML is a popular XML Editor like Internet Explorer, Oxygen Editor, Editplus, Altova XML Spy (I like this the best), or any other supported browser.
<?xml version=”1.0″ encoding=”UTF-8″?>
<snackbar>
<fastfood>
<name id=”10″>burger</name>
<price>10</price>
<calories>1000</calories>
</fastfood>
<drink>
<name id=”20″>pepsi</name>
<price>5</price>
</drink>
</snackbar>
Following is the terminology that I will be using:
roottag: snackbar
childtag: fastfood
grandchildtag: name, price
attribute: id (this is the attribute of the grandchild element in the XML)
The line on the top (<?xml version=”1.0″ encoding=”UTF-8″?>) defines that the structure is of an XML, and helps the browser parse it. One of the best ways to validate a valid XML is to try and open it in a web browser like Internet Explorer. In case of any discrepancies, the document will throw an error and will not open in the Browser.
Following are some of the common XPath expressions:
/ forward slash – used to differentiate between parent and child tags one level deep
// two forward slashes – indicate searches anywhere in the XML, typically more than one level deep
./ indicates the currect XML document passed an input.
.// indicates the need to search multiple levels deep in the document
@ indicates the attribute to a particular tag
* wildcard character to match any tag/element in the XML
Using the above table, if for eg. I need to retrieve the value in the name tag for burger object, I would build the expression as:
./snackbar/fastfood/name
Similarly, for getting the price of ‘pepsi’, I would write:
./snackbar/drink/price
‘Calories’ tag appears just once in the structure, so I can directly use double slashes to retrieve the value ’1000′:
.//calories
To retrieve the value of the attribute for the name ‘pepsi’, I could use:
./snackbar/drink/name/@id
Note: It has been noted that in case a particular tag does not have a value, instead of returning NULL, in some cases Siebel returns the whitespace character, ‘ ‘.
There is more to this. However, what I have covered above are the only ones I have seen working in Siebel successfully.
I have split this blog into parts because of the length. Part II of this article will follow.
Related posts:
- Siebel – Left, Right and from the Middle Extracting a sub string from a lengthy string in Siebel....
- Siebel – FINS Industry XML Query Service “Extracting values from a tag deep down in the Hierarchy.”...
Its really a different way to minimize the code to improve the siebel performance.Is there any way that we can get the XPath notations from LOVs and gets the tag value from the XML file.
Thankyou,
Vijay E
Hi Vijay,
Thanks for your comments.
Yes, I guess that is possible. In that case, instead of putting the value directly in the Input Argument, you would need to do us LookUpValue() in the Workflow, and get the value from the corresponding LOV.
Let me know if this works for you.
i have property set look like (in the watch window of wf simulate) :
-PS:ListOfBc
– PS:Bc
PS:BcName: Service Request
PS:Search:[Status]=Open
– PS:Bc
PS:BcName:Action
PS:Search:[Type]=Debit
when I write .//[BcName] I get Service Reques, what i have to to get the next BcName?
Thank you
Yirat
Hi Yirat,
I guess this is a typical problem that all of us face with the XPath expressions. I see that in your example property set, you have multiple sets of elements with the parent tag as “BC”. Since there is no way to pass through to the second child set even if you use the expanded dot notation, I guess you cannot do it through the XPath expressions.
You will have to use typical XML parsing methods of GetChild(n), GetProperty() combinations etc. This will have to be Custom Script.