[xsd-users] Re: Possible Oversight

Boris Kolpackov boris at codesynthesis.com
Wed May 28 06:50:20 EDT 2008


Hi Manav,

In the future please send technical questions/comments like these
to the xsd-users mailing list (which I've CC'ed) instead of to me
directly. This way other developers who may have experienced a
similar problem can provide you with a solution. Plus questions
and answers will be archived and available to others with similar
problems.


Manav Rathi <manav.rathi at incainformatics.com> writes:

> When using xsd under Windows XP, the anonymous-regex syntax (as specified in
> the help files) does not work. We have to add extra quotes to the entire
> expression.
>
> For example, 
> 
> >xsd --anonymous-regex %.* .* (.*)%$1% test.xsd
> 
> error: invalid anonymous type regex: '%.*': missing second
> pattern-substitution separator
> 
> To fix this, we have to quote the regex string.
> 
> >xsd --anonymous-regex "%.* .* (.*)%$1%" test.xsd
>
> If you already knew this, please update the documentation too :)

It is actually surprisingly tricky to quote regex values in a
portable manner. For example, if you use the above expression
quoted in "" on a POSIX shell (e.g, GNU/Linux, UNIX, etc.) you
will still get the wrong result since $1 is a variable
substitution and will be expanded by the shell. The standard way
of dealing with this on POSIX platforms is to use '' instead of
"" for quoting. The problem is, Windows does not remove '' from
arguments.

As a result we decided to show only the regular expression proper
in the manual without any quoting. It is normally quite easy to
realize that quoting is required. Finding an error when incorrect
quoting is used like in the $1 substitution problem is a lot
trickier since the only indication that there is something wrong
is that the regex doesn't do what you want it to.

You can also save the regular expression options to a file, one
option per line, and use the --options-file option. This way you
don't need to worry about shells and quoting.


> And thanks for this great tool.

You are welcome. I am glad you are enjoying it.


> -Manav
> 
> p.s: By default, xsd names all anonymous types (root or nested) by their
> element name. In case of conflicts, it appends a 1 (or 2, or 3) to the name.
> I thought that instead of this arbitary resolution, it would be better if
> all the names were like parent_element_name__this_element_name. So this
> regex was required.

It is not often that there are conflicts so using the "complete
path" for each type would be an overkill in most cases. Plus you
can always use --anonymous-regex option to transform the names in
pretty much any way you want.


> Ofcourse what would be best is that each nested anonymous type is defined as
> a nested class within the parent types namespace. This way there'll never be
> conflicts between element1::type and element2::type.

It used to work this way. There are two major drawbacks to this
approach. The first is the code bloat which happens when you
reference the same element with anonymous type in two or more
other types. In this situation the same nested type will be
generated in several places. The second drawback is the poor
compiler support for deeply-nested classes.

Boris




More information about the xsd-users mailing list