Skip to content

failed to select node in namespaced target document when using default namespace #9

Description

@henning-meinhardt

Hi,

I have the following XML target file which declares a default namespace along with other namespaces on its root node:

<configuration
	xmlns="urn:configuration"
	xmlns:acl="urn:acl"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="urn:configuration configuration.xsd">
	...

I want to add an attribute the the root tag like so:

<diff xmlns="urn:configuration" xmlns:acl="urn:acl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<add sel="configuration" type="@newAttribute">something</add>
</diff>

Applying that patch fails saying

Caused by: java.lang.RuntimeException: com.github.dnault.xmlpatch.PatchException: no matches for selector "configuration"

Switching over to the following patch file resolves the issue:

<diff xmlns:cfg="urn:configuration" xmlns:acl="urn:acl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<add sel="cfg:configuration" type="@newAttribute">something</add>
</diff>

note that <add>ing new nodes works just find using the default namespace declaration, only selecting does not. So in effect I haver to declare the defaultnamespace twice in order to allow selection and addition of new nodes without having to prefix the added nodes one by one with "cfg:" prefix. See the following example:

<diff xmlns="urn:configuration" xmlns:cfg="urn:configuration" xmlns:acl="urn:acl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<add sel="cfg:configuration">
		<newElement id="something">
			<param name="someName">someValue</param>
			...
		</newElement>
	</add>
</diff>

Without the default namespace I would have to prefix every child node of <add>. Without redundant namespace (prefix "cfg") no selection is possible.

Do you have any solution for that?

Kind regards
Hennig

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions