SQF adds invalid xmlns value in keyword

Having trouble installing Oxygen? Got a bug to report? Post it all here.
urbanrobots
Posts: 86
Joined: Sun May 03, 2015 7:34 pm
Location: San Francisco

SQF adds invalid xmlns value in keyword

Post by urbanrobots »

Hello,

I am new to SQF, so my syntax may be incorrect.

I would like to replace plaintext strings with associated <keyword> elements.

For example, look for "product name" and replace it with "<keyword keyref="prod_name" /> ".

Using SQF, I tried this:

Code: Select all


<pattern>
<rule id="key_001" context="text()">
<report test="contains(., 'Product Name')" sqf:fix="replaceProdName" role="warning"
>key_002: Dolby Digital Plus has a key.</report>

<sqf:fix id="replaceProdName">
<sqf:description>
<sqf:title>Replace product name?</sqf:title>
</sqf:description>

<sqf:stringReplace regex="Product Name"><keyword keyref="prod_name"/>
</sqf:stringReplace>

</sqf:fix>
</rule>
</pattern>
However, this creates invalid XML output:

Code: Select all


<keyword xmlns="http://purl.oclc.org/dsdl/schematron" keyref="prod_name"/>
Which throws the error:
Attribute "xmlns" is not allowed to appear in element "keyword".
What am I doing wrong?

Thanks,
Nick
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Re: SQF adds invalid xmlns value in keyword

Post by Patrik »

I guess that <keyword> should have no namespace at all. But in your schematron file you have most likely declared at the root the default namespace to be "http://purl.oclc.org/dsdl/schematron":

Code: Select all

<schema xmlns="http://purl.oclc.org/dsdl/schematron" ...
Thus, it is applied to all elements without namespace prefix.

One option would be to use a namespace prefix for the schematorn elements:

Code: Select all

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" ...
.

Alternatively you can probably explicitly remove the inherited namespace from the keyword element:

Code: Select all

<keyword xmlns="" keyref="prod_name"/>
Patrik
tavy
Posts: 389
Joined: Thu Jul 01, 2004 12:29 pm

Re: SQF adds invalid xmlns value in keyword

Post by tavy »

Hello,

Patrik response is correct, you need to set a namespace for the inserted element or use a prefix for the Schematron elements.

I always recommend to use a prefix for the Schematron elements. In this way you can insert elements from no namespace without caring about the namespace declaration.

To change the prefix you can use the contextual menu (right click) on an root element and pick Refactoring > Rename Prefix... to manually add a namespace prefix for all the elements from each of those namespaces. Simply introduce the new prefix name (e.g. sch) and select the option Rename current prefix in all document to add that namespace prefix for all the elements from that namespace found in the document.

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
urbanrobots
Posts: 86
Joined: Sun May 03, 2015 7:34 pm
Location: San Francisco

Re: SQF adds invalid xmlns value in keyword

Post by urbanrobots »

Thank you! That worked.
Post Reply