You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Vladimir Sinichkin <si...@barak-online.net> on 2001/09/27 18:06:32 UTC

schema is in string, not in file

Hello,

I am working on a project where xml and schema,specifing the grammar of the xml, are created dinamicly
from the database. There are some reasons that I do not want to write the xml and the schema to files, but keep them in strings.
I am using Xerces C++ 1.5.0 (DOMParser).
I am using MemBufInputSource to pass my xml to the DOMParser, but I have no idea how to pass the schema to the parser without writing it to a file.
Does anybody know how to solve my problem?

Thank you in advance,
Vladimir
sinichkin@barak-online.net
 


Re: schema is in string, not in file

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Vladimir Sinichkin" <si...@barak-online.net> writes:

> Thanx a lot for your recommendations :-) You helped me very much!

Great, glad to hear it. I've learned a bit myself ;-)

> But I still have 2 more small questions:
> 
> 1. Do I have to keep xsi:noNamespaceSchemaLocation='' attribute in my xml
> string?
>     Is there any other way to tell to the parser to use a schema, which I
> provide by EntityResolver?

Apparently not. You just need to supply enough information about the
name of the schema (which gets passed as the systemId argument to
resolveEntity()) so that you get get what you need from your DB.

> 2. As you told me I wrote  subclass from EntityResolver. This class has a
> method
>     resolveEntity that gets 2 arguments:
>     InputSource*  SchemaResolver::resolveEntity(const XMLCh* const publicId,
>                                            const XMLCh* const systemId) ;
>     I need to use those arguments to bring right schema for different
> versions of XMLs.
>     But the bpoblem is that this method is called by the parser (not by ne
> script).
>     So, the question is how can I know what the parser passes in those 2
> arguments?
>     Is there any way to control it?

Right. The parser will invoke resolveEntity() and it will pass the
value of the *SchemaLocation attribute as the systemId argument. So
your entity resolver needs to be able to take the system ID with that
information create the appropriate schema from your DB, and return a
MemBufInputSource to the parser.

HTH,
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: schema is in string, not in file

Posted by Juergen Hermann <jh...@web.de>.
On 27 Sep 2001 12:59:09 -0600, Jason E. Stewart wrote:

>I'm sorry, I don't have example Entity Resolver code in C++.

RTFM. ;)

http://xml.apache.org/xerces-c/apiDocs/class_EntityResolver.html


Ciao, Jürgen



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: schema is in string, not in file

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
Hey Vladimir,

I'm sorry, I don't have example Entity Resolver code in C++. I work on
the Xerces-Perl project and use Xerces-C quite extensively, but all my
example code is in perl.

The issues are:
* create a class that subclasses from EntityResolver, e.g. MyER.
* in your xml files specify the schema that you want to use, but it
  should be unresolvable (i.e. a disk file that doesn't exist)
* in your applications create an instance of you MyER class and tell
  the parser to use it.

  MyER er;
  SAXParser parser;
  parser.setEntityResolver(er);

The entity resolver's resolveEnity() method should be invoked whenever
an external entity (like the schema) does not resolve. Inside you MyER
class's resolveEntity() method, you would create the schema string
from the database (using the information in the PUBLIC and SYSTEM id's
passed as parameters) and then create a MemBufInputSource using the
string, and return it.

jas.

"Vladimir Sinichkin" <si...@barak-online.net> writes:

> Hello, Jason
> Thank you for your advise.
> But I have no idea how to do that.
> Do you have any sample code?
> How to create entity resolver from my string containing a schema?
> How the DOMParser should know to invoke the resolver if xml string has no
> reference to schema?
> 
> Thank you in advance
> Vladimir
> 
> > "Vladimir Sinichkin" <si...@barak-online.net> writes:
> >
> > > I am working on a project where xml and schema,specifing the grammar
> > > of the xml, are created dinamicly from the database. There are some
> > > reasons that I do not want to write the xml and the schema to files,
> > > but keep them in strings.  I am using Xerces C++ 1.5.0 (DOMParser).
> > > I am using MemBufInputSource to pass my xml to the DOMParser, but I
> > > have no idea how to pass the schema to the parser without writing it
> > > to a file.  Does anybody know how to solve my problem?
> >
> > Just as a guess, I would create and entity resolver, and when the
> > parser attempts to find the schema it will invoke your resolver, and
> > your resolver can return a MemBufInputSource with the schema.
> >
> > jas.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
> >

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: schema is in string, not in file

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Vladimir Sinichkin" <si...@barak-online.net> writes:

> I am working on a project where xml and schema,specifing the grammar
> of the xml, are created dinamicly from the database. There are some
> reasons that I do not want to write the xml and the schema to files,
> but keep them in strings.  I am using Xerces C++ 1.5.0 (DOMParser).
> I am using MemBufInputSource to pass my xml to the DOMParser, but I
> have no idea how to pass the schema to the parser without writing it
> to a file.  Does anybody know how to solve my problem?

Just as a guess, I would create and entity resolver, and when the
parser attempts to find the schema it will invoke your resolver, and
your resolver can return a MemBufInputSource with the schema.

jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org