XML Refactoring > Wrap element content

Questions about XML that are not covered by the other forums should go here.
jon45
Posts: 5

XML Refactoring > Wrap element content

Sat Oct 22, 2016 7:15 pm

I'm having a problem using XML Refactoring > Wrap element content

Within an .xml file I want to wrap the contents of all <li> elements in the file with a <p> element e.g
e.g to change a file
from
<li>a</li>
<li>b</li>
to
<li><p>a</p></li>
<li><p>b</p></li>

Error:-
I get the following error when I try and use the "Wrap element content" operation.

"Description: XQST0059: java.io.FileNotFoundException: http://www.oxygenxml.com/ns/xmlRefactor ... commons.xq"



Steps leading to the error above:-

In the XML Refactoring dialog box, for "Wrap element content", I needed to specify three settings:

1. Target elements (XPath)--> I chose "li"

2. Wrapper element, local name --> I chose "p" from the drop-down menu

3.. Namespace --> I chose <NO_NAMESPACE> (I also have experimented with some of the many other namespaces available)


(at the bottom there is a note --> "Each prefix used in an XPath expression must be declared in the Default prefix-namespace mappings section.)

I went to the "Default prefix-namespace mappings", which opens the Preferences dialog box for XML/XSLT-FO-XQuery / XPath

In section "XPath Default Namespace (only for XPath version 2.0)"
I selected radio button "Use the default namespace from the root element"

For "Default prefix-namespace mappings"
I added Prefix = "li" and Namespace URI = "http://www.w3.org/2001/XMLSchema


Questions:-

a) Do I need to add Default prefix-namespace mappings for "li" and "p" ?

b) If yes, which namespace URI do I use for each of these "li" and "p" prefixes?


Thanks in advance.
radu_pisoi
Posts: 327
Location: Craiova

Re: XML Refactoring > Wrap element content

Mon Oct 24, 2016 10:14 am

Hi,

I should admit the error that you get is pretty strange.
jon45 wrote:Questions:-
a) Do I need to add Default prefix-namespace mappings for "li" and "p" ?
b) If yes, which namespace URI do I use for each of these "li" and "p" prefixes?

No, the problem is not related with the namespace of the 'li' element. XML Namespaces provide a method to avoid element name conflicts. However, the namespace 'http://www.w3.org/2001/XMLSchema' is reserved to the XML Schema vocabulary. Please see more about XML Namespaces and prefixes here:
http://www.w3schools.com/xml/xml_namespaces.asp
https://www.w3.org/TR/REC-xml-names/

The problem that you get is rather related to the commons.xq XQuery module that is not correctly resolved. This XQuery module contains some utilities functions and it is located on disk in the XML Refactoring framework directory:

Code: Select all

{oXygenINstallDir}/frameworks/xml_refactoring/libraries/commons/commons.xq.

An XQuery operation references this module by using an import instruction like:

Code: Select all

import module namespace xr = "http://www.oxygenxml.com/ns/xmlRefactoring" at "http://www.oxygenxml.com/ns/xmlRefactoring/resources/commons.xq";

The remote URI is resolved through the XML catalog defined by the XML Refactoring framework

Code: Select all

{oXygenInstallDir}/frameworks/xml_refactoring/catalog.xml

In order to investigate your issue, could you get us more additional details?
1. What oXygen version and distribution(Eclipse, Standalone) are you using?
2. Do you disable the XML Refactoring framework? Check if 'XML Refactoring' framework is disable in Preferences/Document Type Association options page.
3. Do you remove or modify the commons.xq file? Check if commons.xq file exists in the {oXygenInstallDir}/frameworks/xml_refactoring/libraries/commons folder.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
jon45
Posts: 5

Re: XML Refactoring > Wrap element content

Wed Oct 26, 2016 8:15 am

Thanks for your reply.
The answer to your second question
>>2. Do you disable the XML Refactoring framework? Check if 'XML Refactoring' framework is disable in Preferences/Document Type Association options page.
is no.

So I have now enabled "XML Refactoring" in Preferences/Document Type Association options -- Thanks.


Now I have a secondary (XPath) question..if you would like to try and answer it..

Within an xml file, I'd like to wrap the contents of the <li> elements inside a <p> element, but only where the <li> elements do not currently contain a child <p> element.

1.
The following XPath expression wraps the contents of all <li> elements in a <p> element,
whether or not there is a child <p> element, so it is not the solution that I'm looking for.

Target elements (XPath) = "//ul/li"
Wrapper element
Local name ="p"

2.
I tried:-

Target elements (XPath) = "//ul/li/not(p)"
Wrapper element
Local name ="p"


But that did not yield any results.
--i.e When I selected Preview, the
Oxygen message "Could not find any resources that would be affected by this operation" appeared.

and XML Refactoring errors:
...
XPTY0004: Required item type of third argument of xr:compute-qname() is node(); supplied value has item type xs:boolean
...
Required item type of third argument of xr:compute-qname() is node(); supplied value has item type xs:boolean



I would like the last <li> element (containing "Hyper-V") to be selected in the following example:

<ul>
<li>
<p>Live Migration</p>
</li>
<li>
<p>Snapshot</p>
</li>
<li>
<p>Move</p>
</li>
<li>
<p>Export</p>
</li>
<li>
Hyper-V
</li>
</ul>


thanks.
alin
Site Admin
Posts: 128

Re: XML Refactoring > Wrap element content

Wed Oct 26, 2016 4:41 pm

Hello,

Your XPath expression should be:

Code: Select all

//ul/li[not(p)]


Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
jon45
Posts: 5

Re: XML Refactoring > Wrap element content

Fri Oct 28, 2016 12:05 am

Thanks for your reply. I'm nearly there, but frustratingly not quite..
Now, when I use the XPath
//ul/li[not(p)]
, I can see the expected results of the refactoring, when I click "Preview". Only the <li> elements with no child <p> element are selected, which is good.
However when I click "Finish" after "Preview", or I redo the refactoring and just click "Finish", nothing is changed in the XML topic.
:?

I'm using
<oXygen/> XML Author 18.0, build 20160627
The license is one of a group of professional licenses
Another user of Oxygen reports a similar non-result to the one I describe above.

thanks,
alin
Site Admin
Posts: 128

Re: XML Refactoring > Wrap element content

Fri Oct 28, 2016 2:57 pm

Hello,

I can see the expected results of the refactoring, when I click "Preview". Only the <li> elements with no child <p> element are selected, which is good.
However when I click "Finish" after "Preview", or I redo the refactoring and just click "Finish", nothing is changed in the XML topic.


I cannot reproduce your issue with <oXygen/> XML Author 18.0, build 20160627 using a file with the sample XML fragment you provided:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<ul>
    <li>
        <p>Live Migration</p>
    </li>
    <li>
        <p>Snapshot</p>
    </li>
    <li>
        <p>Move</p>
    </li>
    <li>
        <p>Export</p>
    </li>
    <li>
        Hyper-V
    </li>
</ul>


In order to reproduce the issue and find a solution to this problem I would need the following details:
- a sample file on which you have reproduced the problem
- the scope you have selected for the operation
- the filters you have specifed for the operation, if any

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
jon45
Posts: 5

Re: XML Refactoring > Wrap element content

Sat Oct 29, 2016 1:43 am

OK thanks, Do I have the ability to add inline images and attach files to this post?
--John
jon45
Posts: 5

Re: XML Refactoring > Wrap element content

Sat Oct 29, 2016 2:38 am

I sent an example file and other information in an email to Technical Support, that refers back to this topic.

thanks,

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 2 guests