Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLPatched doesn't work with XML namespaces #79

Open
aveXcaesar opened this issue Apr 4, 2024 · 2 comments
Open

XMLPatched doesn't work with XML namespaces #79

aveXcaesar opened this issue Apr 4, 2024 · 2 comments

Comments

@aveXcaesar
Copy link
Contributor

Expected Behavior

Can use XMLPatched with a XML that has XML namespace.

Actual Behavior

Addressing a XML namespace in the Xpath Directive fails.

Steps to reproduce the behavior

The log given by the failure.

Yaapii.Xambly.Error.ImpossibleModificationException : Exception at dir 1: XPATH "/n0:Uos/DataContainer/Part[@uid='Pa__132']/Name" (invalid XPath expr '/n0:Uos/DataContainer/Part[@uid='Pa__132']/Name' (Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.))

Mention any other details that might be useful

Failing example:

var part =
                new XMLPatched(
                    new XMLWithNamespaceResolver(),
                    new Directives()
                    .Xpath("/n0:Uos/DataContainer/Part[@uid='Pa__132']/Name")
                );
@aveXcaesar aveXcaesar added the Bug label Apr 4, 2024
@aveXcaesar
Copy link
Contributor Author

My first idea to solve the bug is to inject a namespace resolver in XMLPatched.
But I don't like the solution because a resolver was already injected to the XML that needs to be patched.

Situation:
I have a XML in my code that needs to work with XPath expressions. I need to inject a namespace resolver to the XML to work with it. Later in the code I need the XMLPatchd object and the resolver again.

It would be nice to have access to the already injected resolver but the current interface design doesn't exposes the resolver. Should we adjust the interface(s)?
What do you think?

@Meerownymous
Copy link
Contributor

Meerownymous commented Aug 17, 2024

I would just test if the xpath contains a namespace prefix and if yes, generate a namespaceresolver based on the xml document's namespaces. Interface adjustment is unnecessary. The resolvers can simply be passed on to new objects through a private or public constructor by the original object.

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

No branches or pull requests

2 participants