Multiple XML Elment Query

Last post 04-13-2016, 2:31 PM by ameykarandikar. 8 replies.
Sort Posts: Previous Next
  • Multiple XML Elment Query
    Posted: 04-13-2016, 11:43 AM

    Howdy,

     

    Saw this online for XPATH query and the ability to query multiple Elements

    Via https://documentation.commvault.com/commvault/v10/articlep=features/workflow/activities.htm

    Example 2

    In this example, the XpathQuery activity is used to read multiple <client>elements from the output of a qoperation execute activity. Then each<client> element is processed in the ForEach activity. The output of the qoperation execute activity returned the XML below:

    <client clientId="337364" clientName="client001"/>
    <client clientId="458504" clientName="client002"/>

    The XpathQuery inputs would be:

    • xml

      xpath:{/workflow/Execute_1/outputXml} - This is the XML output from the qoperation execute activity.

    • xpath

      //client - This is the name of the element.

    • outputType

      XML

    Pass the XML output into the ForEach activity and process each <client>element inside the ForEach block.

     

    I do alot with XML outputs, but I can't seem to get the multiple element query down if its deeper into the XML.

    In the below example I want to return EVERY sublientName in the XML, via the Docs I've tried using this as the xpath variable in the xpath query action:

    /App_GetSubClientPropertiesResponse//subClientProperties/subClientEntity/@subclientName

    or

    //App_GetSubClientPropertiesResponse/subClientProperties/subClientEntity/@subclientName

         Either doesn't work, Any insights on how to do this?

    Sample XML:

    <App_GetSubClientPropertiesResponse>

    <subClientProperties>
     <dfsSubclientProp/>
     <hcSubclientProp/>
     <subClientEntity _type_="SUBCLIENT_ENTITY" appName="Virtual Server" applicationId="106" backupsetId="11" backupsetName="defaultBackupSet" clientId="6" clientName="Junk1" instanceId="2" instanceName="VMware" subclientId="13" subclientName="default"/>
     </subClientProperties>
    <subClientProperties>
     <dfsSubclientProp/>
     <hcSubclientProp/>
     <subClientEntity _type_="SUBCLIENT_ENTITY" appName="Virtual Server" applicationId="106" backupsetId="11" backupsetName="defaultBackupSet" clientId="6" clientName="Junk1" instanceId="2" instanceName="VMware" subclientId="343" subclientName="blah1"/>
     </subClientProperties>
    <subClientProperties>
     <dfsSubclientProp/>
     <hcSubclientProp/>
     <subClientEntity _type_="SUBCLIENT_ENTITY" appName="Virtual Server" applicationId="106" backupsetId="11" backupsetName="defaultBackupSet" clientId="6" clientName="Junk1" instanceId="2" instanceName="VMware" subclientId="2450" subclientName="blah2"/>
     </subClientProperties>
     </App_GetSubClientPropertiesResponse>
  • Re: Multiple XML Elment Query
    Posted: 04-13-2016, 11:50 AM

    can you try with a single forward slash in the beginning?

     

    /App_GetSubClientPropertiesResponse/subClientProperties/subClientEntity/@subclientName

  • Re: Multiple XML Elment Query
    Posted: 04-13-2016, 11:53 AM

    Never mind. I see that you already tried that xpath. Is it that the output of the xpathquery is empty or the for loop is not working on that output?

  • Re: Multiple XML Elment Query
    Posted: 04-13-2016, 11:57 AM

    So if I tried 

    /App_GetSubClientPropertiesResponse/subClientProperties/subClientEntity/@subclientName

    it defaults to the first element, and the attribute to that element (via the example I gave) is "default".

     

     

    What my ultimate goal is, is to grab every attribute of "subclientName" for each element (subClientProperties).

  • Re: Multiple XML Elment Query
    Posted: 04-13-2016, 12:20 PM

    Hey PJValdez, can you check to make sure you've configured the activity to outputAsList?

    Regards

  • Re: Multiple XML Elment Query
    Posted: 04-13-2016, 12:29 PM

    Mind Blown

    Obviously I stopped to read the properties.  However, I'm still getting the same output though, Do I have the Xpath value right?

     

  • Re: Multiple XML Elment Query
    Posted: 04-13-2016, 12:37 PM

    It looks like you are using an InformationalMessage activity here to display the results.  If you just put the xpath expression in the message body then the workflow will only supply the first item in the list to the message string.  If you want all the items to be displayed, then you can put some string in front of the xpath expression like:

    subclients: xpath:{/workflow/XPathQuery_1/result}

     

  • Re: Multiple XML Elment Query
    Posted: 04-13-2016, 1:59 PM

    Nice, thanks for the help. Your right, that was a bad check on my end for using the informational Message, but turning the XPATH query to a List Worked.  

     

    Just curious, if you wanted to query multiple attributes in an element would you have to do that in 2 seperate xpath querries?

  • Re: Multiple XML Elment Query
    Posted: 04-13-2016, 2:31 PM

    if the attributes are in the same element then you can give the parent element name. So if you give this xpath:

    /App_GetSubClientPropertiesResponse/subClientProperties/subClientEntity

    it should output all the attributes of subcliententity

The content of the forums, threads and posts reflects the thoughts and opinions of each author, and does not represent the thoughts, opinions, plans or strategies of Commvault Systems, Inc. ("Commvault") and Commvault undertakes no obligation to update, correct or modify any statements made in this forum. Any and all third party links, statements, comments, or feedback posted to, or otherwise provided by this forum, thread or post are not affiliated with, nor endorsed by, Commvault.
Commvault, Commvault and logo, the “CV” logo, Commvault Systems, Solving Forward, SIM, Singular Information Management, Simpana, Commvault Galaxy, Unified Data Management, QiNetix, Quick Recovery, QR, CommNet, GridStor, Vault Tracker, InnerVault, QuickSnap, QSnap, Recovery Director, CommServe, CommCell, SnapProtect, ROMS, and CommValue, are trademarks or registered trademarks of Commvault Systems, Inc. All other third party brands, products, service names, trademarks, or registered service marks are the property of and used to identify the products or services of their respective owners. All specifications are subject to change without notice.
Close
Copyright © 2019 Commvault | All Rights Reserved. | Legal | Privacy Policy