Project root relative paths
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 7
- Joined: Wed Apr 15, 2015 2:53 pm
Project root relative paths
We have a large project that is split into several files. Is it possible to include files through paths that are relative to the project root directory (i.e not relative to the current file)?
For example:
Is there a way to reference file1 from file2 by saying "a/file1.xml" (relative to the project) instead of "../a/file1.xml" (relative to the file2.xml file) ?
Our current solution is to define an entity "projectRoot" which has the absolute path of the project directory. All other paths are then resolved based on the "projectRoot" entity. This is bad because it is not portable across users and operating systems.
For example:
Code: Select all
root
a
file1.xml
b
file2.xml
Our current solution is to define an entity "projectRoot" which has the absolute path of the project directory. All other paths are then resolved based on the "projectRoot" entity. This is bad because it is not portable across users and operating systems.
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Project root relative paths
Hi,
First I must ask, why do you want to avoid relative references?
They are cross platform and most XML refactoring tools can handle them without issues.
In the long run you would probably be better off with the relative references rather than the hacks needed to avoid them.
Whether this is possible or not, depends on the type of reference and the type of document (DocBook DITA, etc) you're using.
For example, if you're using DocBook with XInclude, it's possible to specify a different base (xml:base) than the current file and every reference will be resolved relative to that specified base. But you will still have to specify explicitly that base at least once on the root of the document by either an absolute URI (file:///...) or a reference relative to the location of the current file (so you would still have to do this at least once per document, or customize the DTD/schema to do this for all).
e.g. file2.xml
There is another way to do something like this with the help of a custom URI and an XML catalog that rewrites that URI, but you will then depend on the XML catalog. The advantage is this is portable.
You need a <protocol>:<name> at the start of every URI. Or you could use a URN (urn:<NID>:<NSS>).
e.g.
Reference in file2: tst:myproject/a/file1.xml
Create the XML catalog file in the project root folder. It will resolve/rewrite the URIs and systemIDs relative to the project root:
Add this XML catalog file in Oxygen's Options > Preferences, XML / XML Catalog.
Regards,
Adrian
First I must ask, why do you want to avoid relative references?
They are cross platform and most XML refactoring tools can handle them without issues.
In the long run you would probably be better off with the relative references rather than the hacks needed to avoid them.
Whether this is possible or not, depends on the type of reference and the type of document (DocBook DITA, etc) you're using.
For example, if you're using DocBook with XInclude, it's possible to specify a different base (xml:base) than the current file and every reference will be resolved relative to that specified base. But you will still have to specify explicitly that base at least once on the root of the document by either an absolute URI (file:///...) or a reference relative to the location of the current file (so you would still have to do this at least once per document, or customize the DTD/schema to do this for all).
e.g. file2.xml
Code: Select all
<article xmlns="http://docbook.org/ns/docbook" version="5.0"
xmlns:xlink="http://www.w3.org/1999/xlink" xml:base="..">
<xi:include href="a/file1.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
...
You need a <protocol>:<name> at the start of every URI. Or you could use a URN (urn:<NID>:<NSS>).
e.g.
Reference in file2: tst:myproject/a/file1.xml
Create the XML catalog file in the project root folder. It will resolve/rewrite the URIs and systemIDs relative to the project root:
Code: Select all
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<rewriteURI uriStartString="tst:myproject/" rewritePrefix="./"/>
<rewriteSystem systemIdStartString="tst:myproject/" rewritePrefix="./"/>
</catalog>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 7
- Joined: Wed Apr 15, 2015 2:53 pm
Re: Project root relative paths
Thank you for your extensive answer, it's good to know that there is a proper solution.
I tried to make your suggestion work in our Docbook based project. In the catalog file I put the following:
And in one of the files that contain a chapter which needs to include a file:
When generating PDF with FOP, Oxygen gives the following error message: SAXException Malformed URL tst:myproject/some_folder/some.xml
Any ideas of what might be wrong?
I tried to make your suggestion work in our Docbook based project. In the catalog file I put the following:
Code: Select all
<catalog prefer="system" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<rewriteURI rewritePrefix="../../" uriStartString="tst:myproject/"></rewriteURI>
<rewriteSystem rewritePrefix="../../" systemIdStartString="tst:myproject/"></rewriteSystem>
....
Code: Select all
<xi:include href="tst:myproject/some_folder/some.xml" xmlns:xi="http://www.w3.org/2001/XInclude"></xi:include>
Any ideas of what might be wrong?
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Project root relative paths
Hi,
What transformation scenario (default or custom) are you running and in what version of Oxygen (Help > About)?
It works for me in v16.1 with the default DocBook PDF transformation scenario.
Oxygen passes the XML catalog as a parameter (-Dxml.catalog.files) when running Apache FOP.
Regards,
Adrian
What transformation scenario (default or custom) are you running and in what version of Oxygen (Help > About)?
It works for me in v16.1 with the default DocBook PDF transformation scenario.
Oxygen passes the XML catalog as a parameter (-Dxml.catalog.files) when running Apache FOP.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 7
- Joined: Wed Apr 15, 2015 2:53 pm
Re: Project root relative paths
I upgraded to 16.1 from 16 but the same error occured. The transformation scenario is customized, so I have to look in to that. I'll report back if I find anything.
Anyway, thank your for the help so far.
Anyway, thank your for the help so far.
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service