sma2006 Outstanding Contributor.
Outstanding Contributor.
81 views

Xpath syntax to read all attributes in a generated query

Jump to solution

Hi,

I'm again ask help to XPATH expert to get information from an XML query.

The source XML/XDS  is a query generated by the REST driver :

<nds dtdversion="3.5" ndsversion="8.x">
<source>
<product build="20181130_1107" instance="Rest Driver" version="1.0.2.0">Identity Manager REST Driver</product>
<contact>NetIQ Corporation.</contact>
</source>
<input>
<query class-name="User">
<search-class class-name="User"/>
<search-attr attr-name="cn ">
<value> *bla</value>
</search-attr>
<read-attr attr-name="CN "/>
<read-attr attr-name=" Surname "/>
<read-attr attr-name=" Given Name "/>
<read-attr attr-name=" Internet Email Address"/>
</query>
</input>
</nds>

 

And I need to get each queried attribute to make some condition, I did that :

<rule>
<description>Check query content - idsa 16 sept 2019</description>
<conditions>
<and>
<if-operation mode="nocase" op="equal">query</if-operation>
<if-xpath op="true">@class-name="User"</if-xpath>
</and>
</conditions>
<actions>
<do-set-local-variable name="ReadAttrName" scope="policy">
<arg-node-set>
<token-xpath expression="$current-op/read-attr/@attr-name[last()]"/>
</arg-node-set>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-xpath expression="$current-node/read-attr/@attr-name"/>
</arg-node-set>
<arg-actions>
<do-set-local-variable name="attrvalue" scope="policy">
<arg-node-set>
<token-xpath expression="$current-value"/>
</arg-node-set>
</do-set-local-variable>
</arg-actions>
</do-for-each>
</actions>
</rule>

I can see all attributes in the local variable ReadAttrName, but the "for each" does not give any value.

 

Any help ?

 

Thanks a lot.

 

Sylvain

Labels (1)
0 Likes
1 Solution

Accepted Solutions
sma2006 Outstanding Contributor.
Outstanding Contributor.

Re: Xpath syntax to read all attributes in a generated query

Jump to solution

Got it.

Changing the variable type for "node set" to string give the right value :

<rule>
<description>Check query content - idsa 16 sept 2019</description>
<conditions>
<and>
<if-operation mode="nocase" op="equal">query</if-operation>
<if-xpath op="true">@class-name="User"</if-xpath>
</and>
</conditions>
<actions>
<do-set-local-variable name="ReadAttrName" scope="policy">
<arg-node-set>
<token-xpath expression="$current-op/read-attr[@attr-name]"/>
</arg-node-set>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-xpath expression="$ReadAttrName[@attr-name]"/>
</arg-node-set>
<arg-actions>
<do-set-local-variable name="attrvalue" scope="policy">
<arg-string>
<token-xpath expression="$current-node/@attr-name"/>
</arg-string>
</do-set-local-variable>
</arg-actions>
</do-for-each>
</actions>
</rule>

The result is :

Performing actions for local-variable(current-node) = <read-attr> @attr-name = " Internet Email Address".
[09/16/19 16:35:21.635]:Rest Driver PT: Action: do-set-local-variable("attrvalue",scope="policy",token-xpath("$current-node/@attr-name")).
[09/16/19 16:35:21.635]:Rest Driver PT: arg-string(token-xpath("$current-node/@attr-name"))
[09/16/19 16:35:21.635]:Rest Driver PT: token-xpath("$current-node/@attr-name")
[09/16/19 16:35:21.635]:Rest Driver PT: Token Value: " Internet Email Address".
[09/16/19 16:35:21.635]:Rest Driver PT: Arg Value: " Internet Email Address".

0 Likes
2 Replies
sma2006 Outstanding Contributor.
Outstanding Contributor.

Re: Xpath syntax to read all attributes in a generated query

Jump to solution

Ok I made this rule :

<rule>
<description>Check query content - 16 sept 2019</description>
<conditions>
<and>
<if-operation mode="nocase" op="equal">query</if-operation>
<if-xpath op="true">@class-name="User"</if-xpath>
</and>
</conditions>
<actions>
<do-set-local-variable name="ReadAttrName" scope="policy">
<arg-node-set>
<token-xpath expression="$current-op/read-attr[@attr-name]"/>
</arg-node-set>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-xpath expression="$ReadAttrName[@attr-name]"/>
</arg-node-set>
<arg-actions>
<do-set-local-variable name="attrvalue" scope="policy">
<arg-node-set>
<token-xpath expression="$current-node/@attr-name"/>
</arg-node-set>
</do-set-local-variable>
</arg-actions>
</do-for-each>
</actions>
</rule>

 

That works better and give each attribute like : Arg Value: {@attr-name = " Internet Email Address"}.

How can I get only the attribute name , Internet Email Address" ?

 

thanks

 

Sylvain

0 Likes
sma2006 Outstanding Contributor.
Outstanding Contributor.

Re: Xpath syntax to read all attributes in a generated query

Jump to solution

Got it.

Changing the variable type for "node set" to string give the right value :

<rule>
<description>Check query content - idsa 16 sept 2019</description>
<conditions>
<and>
<if-operation mode="nocase" op="equal">query</if-operation>
<if-xpath op="true">@class-name="User"</if-xpath>
</and>
</conditions>
<actions>
<do-set-local-variable name="ReadAttrName" scope="policy">
<arg-node-set>
<token-xpath expression="$current-op/read-attr[@attr-name]"/>
</arg-node-set>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-xpath expression="$ReadAttrName[@attr-name]"/>
</arg-node-set>
<arg-actions>
<do-set-local-variable name="attrvalue" scope="policy">
<arg-string>
<token-xpath expression="$current-node/@attr-name"/>
</arg-string>
</do-set-local-variable>
</arg-actions>
</do-for-each>
</actions>
</rule>

The result is :

Performing actions for local-variable(current-node) = <read-attr> @attr-name = " Internet Email Address".
[09/16/19 16:35:21.635]:Rest Driver PT: Action: do-set-local-variable("attrvalue",scope="policy",token-xpath("$current-node/@attr-name")).
[09/16/19 16:35:21.635]:Rest Driver PT: arg-string(token-xpath("$current-node/@attr-name"))
[09/16/19 16:35:21.635]:Rest Driver PT: token-xpath("$current-node/@attr-name")
[09/16/19 16:35:21.635]:Rest Driver PT: Token Value: " Internet Email Address".
[09/16/19 16:35:21.635]:Rest Driver PT: Arg Value: " Internet Email Address".

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.