Saxon - XPATH: how to get rid of namespace specification?

I've many simple self-made XML files without namespace specifications (I don't need them, I just want to keep them minimalist).


Open in new window

However every time I want to get an XPath extraction with a XQuery in Saxon I always have to specify "*" namespace, like this:  "/*:root/*:two"

With Basex I can just write  "/root/two" and it works.

How can I use the minimalist "/root/two" in Saxon too, without modifying my XML files?  what command/switch must I write in the XQuery or in the commandline for Saxon?
Who is Participating?
Geert BormansConnect With a Mentor Information ArchitectCommented:
tagsoup adds the XHTML namespace (unless specified differently)
"Namespaces are suppressed. Normally, all elements are in the XHTML 1.x namespace, and all attributes are in no namespace."

the namespace you are after:

if you are using saxon:parse-html()... I have no idea on how to set the configuation parameter
Geert BormansInformation ArchitectCommented:
Have you set by any chance a default XPath namespace?
If your XML is really pure, Saxon does not need the *: prefix
So your XML either is less namespace free then you think
or you told saxon the default XPath namespace is something other than the null namespace
Geert BormansInformation ArchitectCommented:
is this one of the projects where you are using tagsoup first?
tagsoup sets a default namespace to the xhtml namespace
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

lucavillaAuthor Commented:
I tried with and without a default namespace in the XQwery but I fear that I used Tagsoup in these test, I didn't know that it adds a namespace. Thanks for the info!

I'll check again better and report results...
lucavillaAuthor Commented:
I'm using
'-x:"org.ccil.cowan.tagsoup.Parser"'     command line switch for Saxon

"declare option db:parser 'html';"    XQuery line  for Basex

should I use '-x:"org.ccil.cowan.tagsoup.Parser" -nons'   for Saxon?
and do you know for Basex too?
Geert BormansInformation ArchitectCommented:
Ah, you don't do saxon:parse-html() at all, you use Tagsoup as the underlying parser
that area is really not very well documented.
I don't think Saxon simply picks up the command line settings for TagSoup and passes them on
(a few weeks back I made a java integration of TagSoup in an other context and I had a hard time figuring out how some simple command line parameters for TagSoup were to be passed on through the Java parser call, so I would suspect that Saxonica did not bother too much)
Nothing wrong with trying the --nons option (note, 2 dashes!)
But I fear...

However, you know the namespace after TagSoup, just introduce it in your XQuery

For Basex, I have no real clue
lucavillaAuthor Commented:
I tried '-x:"org.ccil.cowan.tagsoup.Parser" --nons'   and   '-x:"org.ccil.cowan.tagsoup.Parser" --nons' but I've got two different errors...   they didn't work.
Anyway thanks for the info!
lucavillaAuthor Commented:
Sorry I meant:
'-x:"org.ccil.cowan.tagsoup.Parser" --nons'  
'-x:"org.ccil.cowan.tagsoup.Parser --nons"'
Geert BormansInformation ArchitectCommented:
well, I did not expect any of the two to work
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.