0

I am trying to check how to define the xpath in xmltask when processing an xml (change / update / parse etc)

On checking a few stackoverflow posts on similar topics, I could only reach as far as to understand how to "avoid namespaces" { by using ":" before each node's name - /:element1/:subelement1/:childelement2/text() } , when a node doesn't have xmlns prefix to it.

My objective is to update a weblogic xml , which has security namespace prefix defined for several properties , e.g below

    <domain xsi:schemaLocation="http://xmlns.oracle.com/weblogic/security/wls http://xmlns.oracle.com/weblogic/security/wls/1.0/wls.xsd http://xmlns.oracle.com/weblogic/domain http://xmlns.oracle.com/weblogic/1.0/domain.xsd http://xmlns.oracle.com/weblogic/security http://xmlns.oracle.com/weblogic/1.0/security.xsd http://xmlns.oracle.com/weblogic/security/xacml http://xmlns.oracle.com/weblogic/security/xacml/1.0/xacml.xsd" xmlns="http://xmlns.oracle.com/weblogic/domain" xmlns:sec="http://xmlns.oracle.com/weblogic/security" xmlns:wls="http://xmlns.oracle.com/weblogic/security/wls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <name>DOMAIN-NAME</name>
      <domain-version>12.1.3.0.0</domain-version>
      <security-configuration>
        <name>DOMAIN-NAME</name>
        <realm>
          <sec:authentication-provider xsi:type="wls:default-authenticatorType">
            <sec:name>DefaultAuthenticator</sec:name>
          </sec:authentication-provider>
          <sec:authentication-provider xsi:type="wls:default-identity-asserterType">
            <sec:name>DefaultIdentityAsserter</sec:name>
            <sec:active-type>AuthenticatedUser</sec:active-type>
          </sec:authentication-provider>
          <sec:password-validator xsi:type="pas:system-password-validatorType" xmlns:pas="http://xmlns.oracle.com/weblogic/security/providers/passwordvalidator">
            <sec:name>SystemPasswordValidator</sec:name>
              <pas:min-password-length>8</pas:min-password-length>
              <pas:min-numeric-or-special-characters>1</pas:min-numeric-or-special-characters>
          </sec:password-validator>
         </realm>
       </security-configuration>
     </domain>

I tried using the below xmltask command , but it doesn't work as the result is null , meaning that it cannot find a matching node.

    <target name="xml_parse">
      <echo> Executing the task for parsing an XML </echo>
      <xmltask source="src/config.xml">
        <copy path="/*[local-name='domain']/*[local-name='security-configuration']/*[local-name='realm']/*[name='sec:password-validator']/*[name='sec:name']/text()" attrValue="true" property="N1"/>
      </xmltask>
      <if>
        <isset property="N1"/>
      <then>
        <echo message="Value of property = ${N1}"/>
      </then>
      <else>
        <echo message="Value of N1 not set"/>
      </else>
      </if>
    </target>

The output that i get is -

    $ ant xml_parse -f build.xml
Buildfile: /users/fs1/user1/build.xml

xml_parse:
     [echo]  Executing the task for parsing an XML
     [echo] Value of N1 not set

BUILD SUCCESSFUL
Total time: 0 seconds

Any suggestions on how I can achieve parsing the value in the below tag, from above mentioned xml snippet -

<sec:name>SystemPasswordValidator</sec:name>

1 Answer 1

1

You did not call the local-name function. In

[local-name='domain']

you look for a child element named local-name and compare its content with string domain.

Also, in the last two steps you fall back to prefixed names sec:password-validator and sec:name which won't work.

So try this expression:

/*[local-name()='domain']/*[local-name()='security-configuration']/*[local-name()='realm']/*[local-name()='password-validator']/*[local-name()='name']/text()`
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks , that worked ! Is there a way where we can specify namespace prefix in the xpath ?
@ch3tank I'm not familiar with xmltask but according to oopsconsultancy.com/software/xmltask/#examples there does not seem to be any namespace support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.