XPath filter not working with namespaces

Having trouble installing Oxygen? Got a bug to report? Post it all here.
mikasabaggins
Posts: 1
Joined: Thu Apr 02, 2026 10:54 am
Contact:

XPath filter not working with namespaces

Post by mikasabaggins »

Hi everyone,
I’m using Oxygen XML Editor to process an XML file that includes multiple namespaces. I wrote an XPath expression to select specific elements, but it returns no results even though the elements clearly exist in the document.

I suspect it’s related to how namespaces are handled in XPath, but I’m not sure how to properly declare or reference them inside Oxygen. Could someone explain the correct way to use namespace prefixes in XPath within Oxygen, or point out what I might be missing?
teo
Posts: 113
Joined: Wed Aug 30, 2017 3:56 pm

Re: XPath filter not working with namespaces

Post by teo »

Hi,

Apologies for the long delay getting back to this.
We discovered this morning that your post hadn't received any replies.

The most common cause of "XPath returns nothing, but the elements are clearly there" with a namespaced document is this: if the document declares a default namespace (xmlns="..." with no prefix, usually on the root element), every element in it actually belongs to that namespace - even though nothing in the markup "looks" prefixed.
Standard XPath rules say an unprefixed name in your expression (like //item) only matches elements with no namespace, so it silently matches nothing against a namespaced document.

Oxygen has a built-in setting for exactly this: Options > Preferences > XML > XSLT-XQuery > XPath, section "XPath Default Namespace".
By default it's set to "Default namespace of the root" - meaning an unprefixed name in your XPath is automatically matched against the root's own default namespace, if it has one.
That should already cover the most common case (a single default namespace declared on the root).
It's worth checking this hasn't been changed to "No namespace" in your setup.

Two situations it won't cover automatically:
- if a namespace is declared with an actual prefix (xmlns:ns="...") rather than as the default, you need to use that same prefix in your XPath expression, not the bare name.
- if a different default namespace is declared deeper in the document (not on the root), the root-based heuristic above doesn't follow it - you'd need an explicit prefix there too.

Best regards,
Teo
Teodor Timplaru
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply