Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed translated content for 'zh'
Sv translation
languageen
Info
All functions with XML processing support are working with the xPath. We are using xPath as element selector.

 

Available functions

Function

Description

xpathElementAttribute(String content, String xpathExpression, String attributeId)
Returns the value of the attribute specified by attributeId of the element selected by xpathExpression.
xpathElementAttribute(String content, String xpathExpression, String attributeId, String encoding)
Returns the value of the attribute specified by attributeId of the element selected by xpathExpression. Content is in specified encoding.
xpathElementContent(String content, String xpathExpression)
Returns the content of the element selected by xpathExpression.
xpathElementContent(String content, String xpathExpression, String encoding)
Returns the content of the element selected by xpathExpression. Content is in specified encoding.

Examples

Consider following XML content:

Code Block
themeConfluence
<?xml version="1.0" encoding="UTF-8"?>
<Employees>
    <Employee id="3" code="EMPL3">
        <age>40</age>
        <name>Tom</name>
        <gender>Male</gender>
        <role>Manager</role>
    </Employee>
    <Employee id="4" code="EMPL4">
        <age>25</age>
        <name>Meghna</name>
        <gender>Female</gender>
        <role>Manager</role>
    </Employee>
</Employees>

Results:

Code Block
themeEclipse
languagegroovy
linenumberstrue
//get value of attribute of element selected by other attribute
xpathElementAttribute(content, "/Employees/Employee[@id=3]", "code") //returns EMPL3
xpathElementAttribute(content, "/Employees/Employee[@id=4]", "code", "utf-8") //returns EMPL4
 
//get text content of element selected by parent's attribute
xpathElementContent(content, "/Employees/Employee/age[ancestor::Employee[@id=4]]", "utf-8") //returns 25
 
//get text content of first employee element
xpathElementContent(content, "/Employees/Employee/age") //returns 40

Next steps

Sv translation
languageja
Info

XML処理サポートのあるすべての関数は、xPathを使用します。私たちは、要素のセレクタとしてXPathを使用します。

 

利用可能な機能

関数

説明

xpathElementAttribute(String content, String xpathExpression, String attributeId)
xpathExpressionによって選択された要素のattributeIdで指定された属性の値を返却します.
xpathElementAttribute(String content, String xpathExpression, String attributeId, String encoding)
xpathExpressionによって選択された要素のattributeIdで指定された属性の値を返却します。コンテンツは、指定されたencoding(エンコーディング)です。
xpathElementContent(String content, String xpathExpression)
xpathExpressionによって選択された要素のコンテンツを返却します
xpathElementContent(String content, String xpathExpression, String encoding)
xpathExpressionによって選択された要素のコンテンツを返却します。コンテンツは指定されたencoding(エンコーディング)です。

以下のXMLコンテンツを考慮します:

Code Block
themeConfluence
<?xml version="1.0" encoding="UTF-8"?>
<Employees>
    <Employee id="3" code="EMPL3">
        <age>40</age>
        <name>Tom</name>
        <gender>Male</gender>
        <role>Manager</role>
    </Employee>
    <Employee id="4" code="EMPL4">
        <age>25</age>
        <name>Meghna</name>
        <gender>Female</gender>
        <role>Manager</role>
    </Employee>
</Employees>

結果:

Code Block
themeEclipse
languagegroovy
linenumberstrue
//get value of attribute of element selected by other attribute
xpathElementAttribute(content, "/Employees/Employee[@id=3]", "code") //returns EMPL3
xpathElementAttribute(content, "/Employees/Employee[@id=4]", "code", "utf-8") //returns EMPL4
 
//get text content of element selected by parent's attribute
xpathElementContent(content, "/Employees/Employee/age[ancestor::Employee[@id=4]]", "utf-8") //returns 25
 
//get text content of first employee element
xpathElementContent(content, "/Employees/Employee/age") //returns 40

Next steps