[relaxng-user] FW: Jing & Trang errors when processing RNC grammar
Bob Foster
bob at objfac.com
Tue Apr 27 19:21:27 ICT 2004
Hutchison, Ben wrote:
> Hello,
>
> I am considering using RelaxNG for describing the structure of XML
> configuration files used in a enterprise software system, because its
> syntax seems far more intutive than Schemas.
>
> I have developed a grammar by reading the RelaxNG tutorial, but when I
> attempt to validate it using Jing (within OxygenXML) I get an brief
> error message I cannot understand: E "oneOrMore" contains "group"
> contains "attribute"
ConfigGroupEntry* where ConfigGroupEntry has as an alternative
ConfigValue, a group that contains a group, NamedElementAttributes, that
contains two attributes.
The "oneOrMore" reference is because * (zeroOrMore) is defined in RELAX
NG as +? (optional oneOrMore).
NamedElementAttributes is obviously redundant as it is used, so a simple
fix would be to take it out of ConfigValue.
> When I use the inbuilt Trang tool, I can successfully convert the
> compact grammar to XML form, but a conversion on to XML Schema results
> in a message like "Choice between attributes and children cannot be
> presented; approximating", but no schema object is produced.
Trang can't convert everything, esp. an invalid schema, and even if it
did the conversion could not be faithful where there is a choice between
an attribute and an element. XML Schema can't describe this.
> There doesn't seem to be any reference or further explanation for
> parsing errors. I have spent several hours on this and will have to
> abandon the use of RelaxNG unless I can obtain a speedy resolution.
Don't give up. Granted the error messages from jing can be pretty
cryptic, but in this case you had all the info you needed, you just
didn't understand it. OTOH, if you had spent the same several hours
trying to write an XML Schema with no previous knowledge of that
language, I wager you wouldn't be anywhere near as far along as you are. ;-}
> My grammar is shown below, including a leading * indicating the line the
> validator fails on. Note that it relates to the only case of recursion
> in the grammar- a ConfigGroup can contain nested ConfigGroups within
> it. Is anyone able to offer some explanation as to what these problems
> mean? Any general advice on how to "debug" a RelexNG grammar would also
> be appreciated.
First, a grammar isn't thoroughly checked until you try to validate with
it, because some grammars are perfectly ok as fragments but not
acceptable for validation. So exercise the grammar on simple test cases
to make sure it is fully checked and gives you the result you wanted.
Second, compact syntax error messages from jing come in two flavors:
"syntax error," for which the only cure is to stare at the location
identified and consult the syntax until you see the error, and
substantive error messages, like the one you describe, that usually
refer to constraints described in RELAX NG (non-compact)
http://www.oasis-open.org/committees/relax-ng/spec-20011203.html. In
this case, you could have found the restriction by searching the
restriction section for "attribute".
Bob Foster
http://xmlbuddy.com/
> Regards
> Ben Hutchison
> ================================
> namespace rng = "http://relaxng.org/ns/structure/1.0"
> datatypes xsd = "http://www.w3.org/2001/XMLSchema-datatypes"
>
> start = element ConfigRoot { ConfigGroup* }
>
> NamedElementAttributes =
> attribute name { text },
> attribute platform { text }?
>
> StringValue = element StringValue { xsd:string }
> IntValue = element IntValue { xsd:integer }
> FloatValue = element FloatValue { xsd:float }
> BooleanValue = element BooleanValue { xsd:boolean }
> PrimitiveValue = (StringValue | IntValue | FloatValue | BooleanValue)
>
> Map = element Map { (MapEntry)* }
> MapEntry = element MapEntry { PrimitiveValue }
> Array = element Array { (PrimitiveValue)* }
>
> ConfigValue = ( PrimitiveValue | Map | Array ), NamedElementAttributes
>
> ConfigGroupEntry = (ConfigGroup | ConfigValue)
>
> ConfigGroup = element ConfigGroup {
> ConfigGroupEntry*,
> NamedElementAttributes
> }
More information about the relaxng-user
mailing list