Page 1 of 1
XPath request - DTD aware XML - attribute default value
Posted: Tue Nov 15, 2011 6:56 pm
by matthieu.ricaud
Hi all,
I try this xpath request :
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
Re: XPath request - DTD aware XML - attribute default value
Posted: Tue Nov 15, 2011 9:24 pm
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
Re: XPath request - DTD aware XML - attribute default value
Posted: Tue Nov 15, 2011 10:24 pm
by george
You can remove or comment the DOCTYPE declaration, run your XPath and then undo to add back the DTD.
Best Regards,
George
Re: XPath request - DTD aware XML - attribute default value
Posted: Tue Nov 15, 2011 11:27 pm
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.
Re: XPath request - DTD aware XML - attribute default value
Posted: Thu Nov 17, 2011 10:30 am
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