XPath request - DTD aware XML - attribute default value

Oxygen general issues.
matthieu.ricaud
Posts: 20
Joined: Fri Apr 22, 2011 4:17 pm

XPath request - DTD aware XML - attribute default value

Post by matthieu.ricaud »

Hi all,

I try this xpath request :

Code: Select all

//p[not(@align)]
on an XML document with a DOCTYPE declaration.

In the DTD the p/@align attribut is defined with a default value :

Code: Select all

<!ENTITY % attAlign 'align (left|center|right|justify) "justify"'> 
For this reason, the xpath request matches any p element even if no align attribute is defined on it.

I guess this is a normal behaviour, but I'd like to know if there is a way to get an Xpath request that matches only p elements with no @align attribut in the "xml string" ?

Thanks for your help,

Best Regards,
Matthieu.

PS : I used XPath2
adrian
Posts: 2850
Joined: Tue May 17, 2005 4:01 pm

Re: XPath request - DTD aware XML - attribute default value

Post by adrian »

Hello,

XPath works on the XML model of the document which includes the DTD. This means XPath can't tell the difference between the default value of an attribute specified in the DTD and the explicit value of an attribute specified in the XML.

If you want to search the XML text, I recommend using the Find > Find/Replace dialog.
Though I will admit it's somewhat difficult to search in text for strings that do NOT contain a certain keyword.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: XPath request - DTD aware XML - attribute default value

Post by george »

You can remove or comment the DOCTYPE declaration, run your XPath and then undo to add back the DTD.

Best Regards,
George
George Cristian Bina
matthieu.ricaud
Posts: 20
Joined: Fri Apr 22, 2011 4:17 pm

Re: XPath request - DTD aware XML - attribute default value

Post by matthieu.ricaud »

Hi Adrian, Hi George,

Thanks a lot for your both answers.

I actually didn't want to desactivate the DTD neither using the search tool (although with a bit of regex, it could do the trick, for sure).

But I guess I have no choice as I don't see any options to ignore DTD (or ignore xml catalog) while submiting an xpath request.
I don't know if these options might be usefull in the wish list as it's actually not a good XML practice !?

A last solution would be to search this xpath : //p[@align='justify']
as "justify" is the default value defined in the DTD, it will match every p that do not have an @align attribute... + those whose value is "justify", which is XML equivalent. But no way to distinguish them both.

Thanks again for your time, everything is clear.

Cheers,
Matthieu.
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: XPath request - DTD aware XML - attribute default value

Post by george »

Hi Matthieu,

Of course you can use a catalog to direct the actual DTD to an empty DTD and thus remove the default attributes. But that requires setting a catalog to oXygen, run the XPath then remove the catalog... which is a lot more than just commenting the DOCTYPE declaration, run the XPath and uncomment the DOCTYPE declaration.

Best Regards,
George
George Cristian Bina
Post Reply