oXygen XML Editor

Trang QnA

Conversions using Trang

1. Converting from DTD 'ANY'
2. Trang capabilities
3. Trang and comments

1.

Converting from DTD 'ANY'

James Clark


> John Cowan wrote
> The semantics of ANY in a DTD are essentially (#PCDATA|FOO|BAR|BAZ|...)*,
> where FOO, BAR, BAZ, ... are the declared elements in the DTD.  It does
> not mean that "any XML" is permissible here, but that's how Trang
> translates it.

Right. But DTDs don't have real wildcards, so if a DTD author wants a real wildcard, the best they can do is approximate it with ANY. Most of the uses of ANY I've come across are cases of this, rather than people actually wanting the DTD semantics.

In any case, if you want exactly the DTD semantics, trang can give it to you. See the -i strict-any option: thaiopensource.com

2.

Trang capabilities

John Cowan


> element foo { "a"+ }

> is an invalid pattern. However, trang accepts it and converts into
> corresponding XML Syntax.

It is indeed invalid. Trang is not guaranteed to catch errors in input, and when the output is xsd, it may generate erroneous output as well. It's a best-effort program.

3.

Trang and comments

James Clark


> trang translates

> element 
> ( a # case a
> | b # case b
> )
> { empty }

> into

> <?xml version="1.0" encoding="UTF-8"?>
> <element xmlns="http://relaxng.org/ns/structure/1.0">
>   <choice>
>     <name>a</name>
>     <!-- case a -->
>     <name>b</name>
>   </choice>
>   <!-- case b -->
>   <empty/>
> </element>

> moving the second comment past the end of the name class.  
> I realize that translation
> of comments is not normative;  
> however, since the comments are translated by trang,
> is there a list of patterns where comments 
> do not stay in place during translation?

On input, trang associates comments with the next following object (i.e. pattern, name-class, grammar component, annotation). On output, it reverses this. The next object following the "case b" comment is the empty pattern. So on output, the comment will end up before <empty/> element.

This means that the style of commenting in the compact syntax where you put the comment on the same line after the thing it applies doesn't translate well. Perhaps trang could notice when there's no newline between an object and a comment and then associate the comment with the preceding object and flag that in its internal representation, but I think it would be hard to make it always do what a human who actually understood the comment would do.