Page 1 of 1

namespace dependent format and indent

Posted: Fri Jan 26, 2018 1:48 pm
by bwbohl
Hi oXygen team,

I want to configure my Editor to format and indent elements with the same name but from different namespaces differently. E.g. ns1:element should stay inline while ns2:element should have line-breaks before and after. Nevertheless I do not manage to properly configure this in Preferences/Editor/Format/XML.

I did set "ns2:element" in the line-break tab but it seems that the namespace-prefix is not being resolved. It works if I only enter "element" but then it would also affect ns1:element.

What am I doing wrong?

Thanks for helping!

Re: namespace dependent format and indent

Posted: Tue Jan 30, 2018 3:34 pm
by adrian
Hi,

What version of Oxygen are you using?
I did set "ns2:element" in the line-break tab but it seems that the namespace-prefix is not being resolved. It works if I only enter "element" but then it would also affect ns1:element.
I cannot reproduce this issue in v19.1. For me it doesn't work at all with "element", only with ns2:element.

Could you provide a complete (but small) example XML file where you see the issue? It could be something that happens in a specific context.

Do note that Oxygen will already insert some line breaks by default (e.g. in element only blocks). So it's usually more difficult to configure it not to enter line breaks.

Regards,
Adrian

Re: namespace dependent format and indent

Posted: Mon Feb 26, 2018 3:14 pm
by bwbohl
Dear Adrian,

thanks for the reply and sorry for replying late…
I am using oxygen 18.1 on OSX Sierra (see signature ;-)

To give an example:
Let's say we have to namespaces (as I have them configured them in the XPath default namespaces):

mei:xmlns="http://www.music-encoding.org/ns/mei"
tei:xmlns="http://www.tei-c.org/ns/1.0"

To make up an example (N.B. for anyone reading this: this is not cannon TEI or MEI, just a made up example)

Let's say they both define n element <lb/> indicating a line-break in a text and while TEI would define this as marking the start of a new line, MEI would define it as marking the end of a line. So I would configure in "Editor/Format/XML/" Line break Tab:

tei:lb with selected Before
mei:lb with selected After

unfortunately doesn't work out…

the format and indent ignores the configuration, obviously due to the fact that it does not recognise the namespaces elements. With a general rule for "lb" it works though…

Here's the TEI example:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>Title</title>
</titleStmt>
<publicationStmt>
<p>Publication Information</p>
</publicationStmt>
<sourceDesc>
<p>Information about the source</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<p>Some text here.<lb/>yet some more.</p>
</body>
</text>
</TEI>
and the MEI example:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<mei xmlns="http://www.music-encoding.org/ns/mei" meiversion="4.0.0">
<meiHead>
<fileDesc>
<titleStmt>
<title/>
</titleStmt>
<pubStmt/>
</fileDesc>
</meiHead>
<music>
<body>
<div>
<p>Some text here.<lb/>yet some more.</p>
</div>
<mdiv>
</mdiv>
</body>
</music>
</mei>

Re: namespace dependent format and indent

Posted: Mon Feb 26, 2018 6:09 pm
by adrian
Hello,

I see the problem now. The thing is the XML formatting options aren't actually namespace aware (namespace prefixes don't get resolved), they are only namespace prefix-aware.
bwbohl wrote:Let's say we have to namespaces (as I have them configured them in the XPath default namespaces):

mei:xmlns="http://www.music-encoding.org/ns/mei"
tei:xmlns="http://www.tei-c.org/ns/1.0"
The "Default prefix-namespace mappings" declared in Preferences > XML / XSLT-FO-XQuery / XPath only apply to the XPath tools (XPath toolbar and XPath/XQuery Builder). These namespace mappings do not apply to the formatting options, so mei:lb and tei:lb have no effect there, as the prefixes mei and tei are never resolved.
Another thing to add is that only simple XPath expressions can be used in the formatting options:
//xs:localName Note: The namespace prefixes (such as xs) are treated as part of the element name without taking its binding to a namespace into account.
This means you cannot actually specify the namespace for the formatter, just the namespace prefix, as part of the element name.

To clarify, for your particular situation (default namespace on the root and same local name for element), you cannot configure the Oxygen formatter to distinguish between the two 'lb' elements from different namespaces.

Regards,
Adrian

Re: namespace dependent format and indent

Posted: Tue Feb 27, 2018 2:21 pm
by bwbohl
If I get you right it would not be possible to enter something like:

Code: Select all


lb[namespace-uri()='http://www.tei-c.org/ns/1.0 ']
because it does supersede the implemented simplified XPath.

If I'd consequently use prefixes in my XML-files, though, as in this modified example from above:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<tei:TEI xmlns:tei="http://www.tei-c.org/ns/1.0">
<tei:teiHeader>
<tei:fileDesc>
<tei:titleStmt>
<tei:title>Title</tei:title>
</tei:titleStmt>
<tei:publicationStmt>
<tei:p>Publication Information</tei:p>
</tei:publicationStmt>
<tei:sourceDesc>
<tei:p>Information about the source</tei:p>
</tei:sourceDesc>
</tei:fileDesc>
</tei:teiHeader>
<tei:text>
<tei:body>
<tei:p>Some text here.
<tei:lb/>yet some more.</tei:p>
</tei:body>
</tei:text>
</tei:TEI>
it works!

Thanks, very valuable tip!
Nevertheless I'd opt for a section in the preferences where one can define application-wide (global or project specific) namespace prefixes. You may consider this a feature request ;-)