[xsd-users] "Unable to open in read mode" using --namespace-regex

Lenz, Timothy K timothy.k.lenz at lmco.com
Wed Mar 26 09:09:40 EDT 2008


Boris:

Thanks for the reply!

First, I see your point with the ".* " at the beginning of the query.  I
had read that in the man pages and eventually tried it yesterday
afternoon, but it didn't change the outcome of my attempt.  I neglected
to put that in my original email...

I tried the regular expression you provided (which is actually very
close to some of the later variations I had tried) and still got the
same problem.  Here is the error message I get when running
--namespace-regex-trace:

%.* (\w+):(\w+)%$1::$2%: error: '%.* (\w+):(\w+)%$1::$2%': error: unable
to open in read mode

The error makes no mention of the xsd file.  I've verified the file I am
passing in exists and is readable.  My initial attempts were using
wildcards in another directory (e.g. /foo/bar/*.xsd) as the target, but
I even copied one of the files to the current directory and ran it on
that exclusively.  Same error every time.

PS:  I definitely read the section about this namespace-regex stuff in
the man pages.  What I meant in my previous post was there was no full
example of a command line using this functionality (I wanted to make
sure I had everything in the right place, syntactically correct, etc).
There was only an example regular expression, not an example command.

Tim Lenz

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Tuesday, March 25, 2008 5:06 PM
To: Lenz, Timothy K
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] "Unable to open in read mode" using
--namespace-regex

Hi Timothy,

Lenz, Timothy K <timothy.k.lenz at lmco.com> writes:

> I've only recently started using Code Synthesis XSD for a medium-scale
> application.  We are in the process of trying multiple XML/C++ binding
> tools to find one that best fits our needs.  In that light, I am
pretty
> new to most of this stuff (XML namespaces and schemas, Perl regular
> expressions, etc), so be gentle.  This could be an entirely simple
> issue, but I can't find out how to fix it.

No problem, welcome aboard!


> These don't translate to valid C++ namespaces, so I need to replace
all
> of those single colons with double colons.  However, every time I try,
I
> get the error "Unable to open in read mode".

This error would normally mean that the input schema file does not
exist. One cause of this might be that you don't put a regular
expression with spaces in "" or '' but it seems that all your
expressions are in "".


> I have tried various permutations of the following command:
>
> /usr/bin/xsd cxx-tree --namespace-regex "%(\w):{1}(\w)%\$1::\$2%"
myfile.xsd

There are a couple of problems with this expression:

1. The format string is in the form "<file-name> <namespace>" where
   filename is the name of the schema file being processed. It is
   empty for the file name being translated (myfile.xsd in your case).
   This is all described in the man pages. Also, the
   --namespace-regex-trace option is often useful when trying to figure
   why your expression are not working.

2. The part that is matching words should allow for multiple characters,
   not just one.

In the end I successfully used the following expression on a schema
that has "foo:bar" as target namespace:

--namespace-regex "/.* (\w+):(\w+)/\$1::\$2/"

Also, you may want to use '' instead of "" to quote regular expressions
on Linux/UNIX since then you don't need to escape $:


--namespace-regex '/.* (\w+):(\w+)/$1::$2/'


> How do I use this?  The "man" pages were pretty useless on this point
> (no actual example using namespace-regex).

Hm, that's strange. Here is the documentation for the --namespace-regex
option from the man pages:

--namespace-regex regex
    Add regex to the list of regular expressions used to translate XML
    Schema namespace names to C++ namespace names. regex is a perl-like
    regular expression in the form /pattern/replacement/. Any character
    can be used as a delimiter instead of /. Escaping of the delimiter
    character in pattern or replacement is not supported.

    All regular expressions are pushed into a stack with the last
    specified expression considered first. The first match that succeeds
    is used. Regular expressions are applied to a string in the form

    filename namespace

    For example,

    XMLSchema.xsd http://www.w3.org/2001/XMLSchema

    The filename for the current translation unit is empty. For example,
    if you have file hello.xsd with namespace http://example.com/hello
    and you run xsd on this file, then the string in question would be:

     http://example.com/hello

    Note the leading space.

    The following three steps are performed for each regular expression
    until the match is found:

       1. The expression is applied and if the result is empty the next
          expression is considered.

       2. All / are replaced with ::.

       3. The result is verified to be a valid C++ scope name (e.g.,
          foo::bar). If this test succeeds, the result is used as a C++
          namespace name.

    As an example, the following expression maps XML Schema namespaces
    in the form http://example.com/foo/bar to C++ namespaces in the form
    foo::bar:

    %.* http://example.com/(.+)%$1%


Boris




More information about the xsd-users mailing list