Schematic Model Manager
User Guide
Appendices
: Appendix C: XPath Expressions
Appendix C: XPath Expressions
XPath Expressions can be used when mapping system/project specific attributes from the source files to schematic or user defined database attributes. See
XPath Expression Builder Dialog
.
This Appendix provides a brief guide to the use of XPath Expressions. For further information refer to:
http://www.w3.org/TR/xpath
.
Within an Expression:
•
XML element names are represented in their simplest form as the tag name, e.g. <MyElement> is represented as MyElement.
•
XML attribute names in their simplest form are prefixed with the @ character, e.g. the attribute MyAttribute=”value” is represented as @MyAttribute
•
An expression is built up from a series of these LocationPaths separated by the ‘/’ character. For example the attribute from <MyElement @MyAttribute /> may be obtained using MyElement/@MyAttribute
•
More complex LocationPaths exist, such as:
Long form
Short Form
Description
child::MyElement
MyElement
MyElement child element of the current context
attribute::MyAttribute
@MyAttribute
MyAttribute XML attribute of the current context
child::*
*
all child elements of the current context
attribute::*
@
all attributes of the current context
parent::*
..
The parent element of the current context
ancestor::MyElement
The MyElement element that the current context is in
self ::*
.
The current context
/descendants::*
//*
all XML elements of the document
self::*//
//
all descendant XML element of the current context
following-sibling::*
The next XML element if one exists as a child of the same parent element
preceding-sibling::*
the previous element that is a child of the same parent element as the current context
•
Predicates can be added to each LocationPath in order to further constrain the selected nodes. Predicates are enclosed inside ‘[‘ and ‘]’ characters. For example:
MyElement[@MyAttribute] selects MyElement XML elements that have an attribute with the name MyAttribute
MyElement[@MyAttribute = ‘Motor’] selects the MyElement XML elements that have an attribute with the name MyAttribute that has a value of ‘Motor’
MyElement[1] selects the first MyElement child of the current context
MyElement[last()] selects the last MyElement child of the current context
•
Data can then be manipulated using functions such as:
normalize-space(MyElement) takes the textual contents from the MyElement element and replaces all whitespace with a single space character
translate(MyElement/@Tag,’-‘,’_’) replaces and ‘-‘ characters with a ‘_’ character from the Tag attribute of MyElement
concat(MyElement[1],MyElement[2]) concatenates the results of MyElement[1] and MyElement[2]
count(MyElement) The number of MyElement elements in the current context
name(.) Name of the current element (including namespace)
local-name(.) the local name of the current element (excluding namespace)
•
A Boolean expression is one that returns a value of True or False. This is usually achieved using an equivalence or existence test such as:
@MyAttribute = ‘SomeValue’ MyAttribute has a value of SomeValue
@MyAttribute MyAttribute present on current context
Count(MyElement) = 1 1 element named MyElement in the current context
1974 to current year.
AVEVA Solutions Limited and its subsidiaries. All rights reserved.