0

How do i find a text() node in XmlConfig and use it to remove the parent nodeset. All the examples I have seen just find and remove the 'found' node not the parent nodes.

My understanding is that this Xpath finds the matching node via verify path and ElementPath is the path of the nodes to remove. However Its not working at all.

Is text() supported?, I have tried [[*='ATrigger'[]], [[].='ATrigger'[]] but still no luck.

        <util:XmlConfig Id="RemoveATriggerCompletely" File="[#QuartzXmlJob]" Sequence="104" Action="delete" On ="install" Node="element"
            ElementPath="//job-scheduling-data/schedule/" 
            VerifyPath="//job-scheduling-data/schedule/trigger/cron/name[\[]text()='ATrigger'[\]]"/>

Given the following XML

<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
<schedule>
    <trigger>
        <cron>
            <name>ATrigger</name>
            <group>default</group>
            <description>Every 2 minutes</description>
            <job-name>ATriggerJob</job-name>
            <job-group>defaultGroup</job-group>
            <misfire-instruction>SmartPolicy</misfire-instruction>
            <!-- every 5mins -->
            <cron-expression>2 * * * * ?</cron-expression> 
        </cron>
    </trigger>

    <trigger>
        <cron>
            <name>BTrigger</name>
            <group>default</group>
            <description>Every 2 minutes</description>
            <job-name>BTriggerJob</job-name>
            <job-group>defaultGroup</job-group>
            <misfire-instruction>SmartPolicy</misfire-instruction>
            <!-- every 5mins -->
            <cron-expression>2 * * * * ?</cron-expression> 
        </cron>
    </trigger>

The output i require is

<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
<schedule>
    <trigger>
        <cron>
            <name>BTrigger</name>
            <group>default</group>
            <description>Every 2 minutes</description>
            <job-name>BTriggerJob</job-name>
            <job-group>defaultGroup</job-group>
            <misfire-instruction>SmartPolicy</misfire-instruction>
            <!-- every 5mins -->
            <cron-expression>2 * * * * ?</cron-expression> 
        </cron>
    </trigger>

I have been banging my head against a wall for hours now so any help whatsoever is very much appreciated.

PingCrosby
  • 369
  • 4
  • 17

1 Answers1

0

I'm not familiar with that "XmlConfig" task.

But I see two issues.

You need to alias the namespace and use that alias for the xpath "select".

I show the XmlPeek version below. Note I use "peanut", you can use any alias name you want.

Note the query now has "peanut:" in all the element names.

<!-- you do not need a namespace for this example, but I left it in for future reference -->
<XmlPeek Namespaces="&lt;Namespace Prefix='peanut' Uri='http://quartznet.sourceforge.net/JobSchedulingData'/&gt;"
     XmlInputPath=".\Parameters.xml" 
     Query="//peanut:job-scheduling-data/peanut:schedule/peanut:trigger/peanut:cron/peanut:name[text()='ATrigger']/../..">
    <Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>

Note my "../.."

Once you find the correct element, finding its parent(s) is simple as the ".." notation.

You'll need to figure out how to add the namespace and alias to your Task (XmlConfig)

APPEND:

http://sourceforge.net/p/wix/bugs/2384/

Hmmm...dealing with a namespace isn't trivial. I think you're having a similar issue to what is reported there.

APPEND:

"Inline" Namespacing ... (Yuck)

<XmlPeek
     XmlInputPath=".\Parameters.xml" 
     Query="//*[local-name()='job-scheduling-data' and namespace-uri()='http://quartznet.sourceforge.net/JobSchedulingData']/*[local-name()='schedule' and namespace-uri()='http://quartznet.sourceforge.net/JobSchedulingData']/*[local-name()='trigger' and namespace-uri()='http://quartznet.sourceforge.net/JobSchedulingData']/*[local-name()='cron' and namespace-uri()='http://quartznet.sourceforge.net/JobSchedulingData']/*[local-name()='name' and namespace-uri()='http://quartznet.sourceforge.net/JobSchedulingData'][text()='ATrigger']/../..">
    <Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>

Aka, try this Xpath:

"//*[local-name()='job-scheduling-data' and namespace-uri()='http://quartznet.sourceforge.net/JobSchedulingData']/*[local-name()='schedule' and namespace-uri()='http://quartznet.sourceforge.net/JobSchedulingData']/*[local-name()='trigger' and namespace-uri()='http://quartznet.sourceforge.net/JobSchedulingData']/*[local-name()='cron' and namespace-uri()='http://quartznet.sourceforge.net/JobSchedulingData']/*[local-name()='name' and namespace-uri()='http://quartznet.sourceforge.net/JobSchedulingData'][text()='ATrigger']/../.."
granadaCoder
  • 26,328
  • 10
  • 113
  • 146
  • This might help: http://stackoverflow.com/questions/23472654/add-namespace-in-xpath-in-xmlfile-element-wix-util-extension – granadaCoder Mar 06 '15 at 21:01
  • Added info for "inline" namespacing. Now I know why they invented aliaseseseses....(or aliai !) – granadaCoder Mar 06 '15 at 21:30
  • Hi thanks for this - i originally tried the local-name() and no joy using what i learned from this http://stackoverflow.com/questions/22414628/trying-to-replace-xml-element-element-using-xdt-and-xpath-locator/25080456#25080456. Not sure its a namespace thing as I can actually remove nodes using the notation /job-scheduling-data/schedule/trigger/cron/, its just when i get to the search on the text value that issues occur. – PingCrosby Mar 07 '15 at 19:02
  • Thanks for the headsup on XmlPeek thats a completely new one to me. I am off to have a read – PingCrosby Mar 07 '15 at 19:04
  • You could try "RemoveElement" http://www.msbuildextensionpack.com/help/3.5.11.0/html/4009fe8c-73c1-154f-ee8c-e9fda7f5fd96.htm This extension supports namespaces. – granadaCoder Mar 08 '15 at 03:46
  • https://msbuildextensionpack.codeplex.com/SourceControl/latest#Solutions/Main/Framework/Xml/XmlFile.cs – granadaCoder Mar 08 '15 at 03:48
  • Or this one: http://stackoverflow.com/questions/4526847/msbuild-xmlupdate-delete-node-in-web-config – granadaCoder Mar 08 '15 at 03:51