You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Dan Arcari <da...@gmail.com> on 2008/05/12 20:05:18 UTC

Using MemBufInputSource with DOM parser

Hello,

We have a library written on top of Xerces-c which uses DOM parsing of
file-based XML. We would like to be able to send a MemBufInputSource (or
derivation) via our library to xerces so we can parse XML which does not
reside in a file. Is this possible, and could anyone share some examples or
advice on how to go about this?

Thanks

Re: Using MemBufInputSource with DOM parser

Posted by Dan Arcari <da...@gmail.com>.
Thanks Alberto. This was successful!

On Mon, May 12, 2008 at 5:17 PM, Alberto Massari <am...@datadirect.com>
wrote:

>  Wrapper4InputSource wrap(memIS, false);
>  mParser->parse(wrap);
>
>
> Alberto
>
>
>
> Sahoglu, Ozgur wrote:
>
> > Dan,
> >
> > Remove the cast in the parse() method. MemBufInputSource is-a
> > InputSource. Use this code instead:
> >
> > MemBufInputSource* memIS = new MemBufInputSource((const XMLByte
> > *)someXML, strlen(someXML), "test", false);
> >
> > mParser->parse(*memIS);
> >
> >
> > Cheers,
> >
> >
> > -Ozgur Sahoglu
> >
> >
> > -----Original Message-----
> > From: Dan Arcari [mailto:danarcari@gmail.com] Sent: Monday, May 12, 2008
> > 4:42 PM
> > To: c-users@xerces.apache.org
> > Subject: Re: Using MemBufInputSource with DOM parser
> >
> > Thanks Ozgur.
> >
> > I have attempted to do the following:
> >
> > static const char* someXML = "<?xml version="\1.0\" encoding=\"ascii\"
> > ?><message>Hello World</message>";
> > XMLCh* testData = XMLString::transcode(someXML);
> > XMLByte* pXMLByte = reinterpret_cast<XMLByte*>(testData);
> >
> > MemBufInputSource* memIS = new MemBufInputSource(pXMLByte,
> > strlen(someXML),
> > "test", false);
> >
> > mParser->parse((const DOMInputSource&)memIS);
> >
> > ---
> > //mParser is created as:
> > mParser =
> > ((DOMImplementationLS&)impl)->createDOMBuilder(DOMImplementationLS::MODE
> > _SYNCHRONOUS,
> > 0);
> >
> >
> > Using this code, I receive a segmentation fault in ReaderMgr where it
> > attempts to call src.makeStream().
> >
> > Do I need to prepare my memIS object some other way so that it will
> > properly
> > provide a BinInputStream object to the functions farther down the line?
> >
> > Thanks,
> >
> > Dan
> >
> > On Mon, May 12, 2008 at 12:48 PM, Sahoglu, Ozgur
> > <Oz...@intuit.com>
> > wrote:
> >
> >
> >
> > > Hi Dan,
> > >
> > > Parsing a file is no different than parsing a memory buffer (or any
> > > other input source). They all use BinInputStream internally if you
> > >
> > >
> > look
> >
> >
> > > at the Xerces-C++ implementation. All you need to do is create the
> > > MemBufInputSource and pass it to parser's parse() method (see the API
> > > doc
> > >
> > >
> > >
> > http://xerces.apache.org/xerces-c/apiDocs/classAbstractDOMParser.html#b6
> >  fbd6cdf84cce77db1c780017d107dd<
> > http://xerces.apache.org/xerces-c/apiDocs
> > /classAbstractDOMParser.html#b6fbd6cdf84cce77db1c780017d107dd>
> >
> >
> > > ).
> > >
> > > DOM parser's parse() method is overloaded to accept a system id (a
> > >
> > >
> > file
> >
> >
> > > path or URL) or an InputSource, which can be a LocalFileInputSource, a
> > > URLInputSource, a StdInInputSource, a Wrapper4DOMInputSource, or a
> > > MemBufInputSource (see
> > > http://xerces.apache.org/xerces-c/apiDocs/classInputSource.html).
> > >
> > > Cheers,
> > >
> > >
> > > -Ozgur Sahoglu
> > >
> > > -----Original Message-----
> > > From: Dan Arcari [mailto:danarcari@gmail.com]
> > > Sent: Monday, May 12, 2008 11:05 AM
> > > To: c-users@xerces.apache.org
> > > Subject: Using MemBufInputSource with DOM parser
> > >
> > > Hello,
> > >
> > > We have a library written on top of Xerces-c which uses DOM parsing of
> > > file-based XML. We would like to be able to send a MemBufInputSource
> > >
> > >
> > (or
> >
> >
> > > derivation) via our library to xerces so we can parse XML which does
> > >
> > >
> > not
> >
> >
> > > reside in a file. Is this possible, and could anyone share some
> > >
> > >
> > examples
> >
> >
> > > or
> > > advice on how to go about this?
> > >
> > > Thanks
> > >
> > >
> > >
> >
> >
> >
> >
>
>
>

Re: Using MemBufInputSource with DOM parser

Posted by Alberto Massari <am...@datadirect.com>.
  Wrapper4InputSource wrap(memIS, false);
  mParser->parse(wrap);


Alberto


Sahoglu, Ozgur wrote:
> Dan,
>
> Remove the cast in the parse() method. MemBufInputSource is-a
> InputSource. Use this code instead:
>
> MemBufInputSource* memIS = new MemBufInputSource((const XMLByte
> *)someXML, strlen(someXML), "test", false);
>
> mParser->parse(*memIS);
>
>
> Cheers,
>
>
> -Ozgur Sahoglu
>
>
> -----Original Message-----
> From: Dan Arcari [mailto:danarcari@gmail.com] 
> Sent: Monday, May 12, 2008 4:42 PM
> To: c-users@xerces.apache.org
> Subject: Re: Using MemBufInputSource with DOM parser
>
> Thanks Ozgur.
>
> I have attempted to do the following:
>
> static const char* someXML = "<?xml version="\1.0\" encoding=\"ascii\"
> ?><message>Hello World</message>";
> XMLCh* testData = XMLString::transcode(someXML);
> XMLByte* pXMLByte = reinterpret_cast<XMLByte*>(testData);
>
> MemBufInputSource* memIS = new MemBufInputSource(pXMLByte,
> strlen(someXML),
> "test", false);
>
> mParser->parse((const DOMInputSource&)memIS);
>
> ---
> //mParser is created as:
> mParser =
> ((DOMImplementationLS&)impl)->createDOMBuilder(DOMImplementationLS::MODE
> _SYNCHRONOUS,
> 0);
>
>
> Using this code, I receive a segmentation fault in ReaderMgr where it
> attempts to call src.makeStream().
>
> Do I need to prepare my memIS object some other way so that it will
> properly
> provide a BinInputStream object to the functions farther down the line?
>
> Thanks,
>
> Dan
>
> On Mon, May 12, 2008 at 12:48 PM, Sahoglu, Ozgur
> <Oz...@intuit.com>
> wrote:
>
>   
>> Hi Dan,
>>
>> Parsing a file is no different than parsing a memory buffer (or any
>> other input source). They all use BinInputStream internally if you
>>     
> look
>   
>> at the Xerces-C++ implementation. All you need to do is create the
>> MemBufInputSource and pass it to parser's parse() method (see the API
>> doc
>>
>>     
> http://xerces.apache.org/xerces-c/apiDocs/classAbstractDOMParser.html#b6
>   
> fbd6cdf84cce77db1c780017d107dd<http://xerces.apache.org/xerces-c/apiDocs
> /classAbstractDOMParser.html#b6fbd6cdf84cce77db1c780017d107dd>
>   
>> ).
>>
>> DOM parser's parse() method is overloaded to accept a system id (a
>>     
> file
>   
>> path or URL) or an InputSource, which can be a LocalFileInputSource, a
>> URLInputSource, a StdInInputSource, a Wrapper4DOMInputSource, or a
>> MemBufInputSource (see
>> http://xerces.apache.org/xerces-c/apiDocs/classInputSource.html).
>>
>> Cheers,
>>
>>
>> -Ozgur Sahoglu
>>
>> -----Original Message-----
>> From: Dan Arcari [mailto:danarcari@gmail.com]
>> Sent: Monday, May 12, 2008 11:05 AM
>> To: c-users@xerces.apache.org
>> Subject: Using MemBufInputSource with DOM parser
>>
>> Hello,
>>
>> We have a library written on top of Xerces-c which uses DOM parsing of
>> file-based XML. We would like to be able to send a MemBufInputSource
>>     
> (or
>   
>> derivation) via our library to xerces so we can parse XML which does
>>     
> not
>   
>> reside in a file. Is this possible, and could anyone share some
>>     
> examples
>   
>> or
>> advice on how to go about this?
>>
>> Thanks
>>
>>     
>
>
>   



RE: Using MemBufInputSource with DOM parser

Posted by "Sahoglu, Ozgur" <Oz...@intuit.com>.
Dan,

Remove the cast in the parse() method. MemBufInputSource is-a
InputSource. Use this code instead:

MemBufInputSource* memIS = new MemBufInputSource((const XMLByte
*)someXML, strlen(someXML), "test", false);

mParser->parse(*memIS);


Cheers,


-Ozgur Sahoglu


-----Original Message-----
From: Dan Arcari [mailto:danarcari@gmail.com] 
Sent: Monday, May 12, 2008 4:42 PM
To: c-users@xerces.apache.org
Subject: Re: Using MemBufInputSource with DOM parser

Thanks Ozgur.

I have attempted to do the following:

static const char* someXML = "<?xml version="\1.0\" encoding=\"ascii\"
?><message>Hello World</message>";
XMLCh* testData = XMLString::transcode(someXML);
XMLByte* pXMLByte = reinterpret_cast<XMLByte*>(testData);

MemBufInputSource* memIS = new MemBufInputSource(pXMLByte,
strlen(someXML),
"test", false);

mParser->parse((const DOMInputSource&)memIS);

---
//mParser is created as:
mParser =
((DOMImplementationLS&)impl)->createDOMBuilder(DOMImplementationLS::MODE
_SYNCHRONOUS,
0);


Using this code, I receive a segmentation fault in ReaderMgr where it
attempts to call src.makeStream().

Do I need to prepare my memIS object some other way so that it will
properly
provide a BinInputStream object to the functions farther down the line?

Thanks,

Dan

On Mon, May 12, 2008 at 12:48 PM, Sahoglu, Ozgur
<Oz...@intuit.com>
wrote:

>
> Hi Dan,
>
> Parsing a file is no different than parsing a memory buffer (or any
> other input source). They all use BinInputStream internally if you
look
> at the Xerces-C++ implementation. All you need to do is create the
> MemBufInputSource and pass it to parser's parse() method (see the API
> doc
>
http://xerces.apache.org/xerces-c/apiDocs/classAbstractDOMParser.html#b6
>
fbd6cdf84cce77db1c780017d107dd<http://xerces.apache.org/xerces-c/apiDocs
/classAbstractDOMParser.html#b6fbd6cdf84cce77db1c780017d107dd>
> ).
>
> DOM parser's parse() method is overloaded to accept a system id (a
file
> path or URL) or an InputSource, which can be a LocalFileInputSource, a
> URLInputSource, a StdInInputSource, a Wrapper4DOMInputSource, or a
> MemBufInputSource (see
> http://xerces.apache.org/xerces-c/apiDocs/classInputSource.html).
>
> Cheers,
>
>
> -Ozgur Sahoglu
>
> -----Original Message-----
> From: Dan Arcari [mailto:danarcari@gmail.com]
> Sent: Monday, May 12, 2008 11:05 AM
> To: c-users@xerces.apache.org
> Subject: Using MemBufInputSource with DOM parser
>
> Hello,
>
> We have a library written on top of Xerces-c which uses DOM parsing of
> file-based XML. We would like to be able to send a MemBufInputSource
(or
> derivation) via our library to xerces so we can parse XML which does
not
> reside in a file. Is this possible, and could anyone share some
examples
> or
> advice on how to go about this?
>
> Thanks
>

Re: Using MemBufInputSource with DOM parser

Posted by Dan Arcari <da...@gmail.com>.
Thanks Ozgur.

I have attempted to do the following:

static const char* someXML = "<?xml version="\1.0\" encoding=\"ascii\"
?><message>Hello World</message>";
XMLCh* testData = XMLString::transcode(someXML);
XMLByte* pXMLByte = reinterpret_cast<XMLByte*>(testData);

MemBufInputSource* memIS = new MemBufInputSource(pXMLByte, strlen(someXML),
"test", false);

mParser->parse((const DOMInputSource&)memIS);

---
//mParser is created as:
mParser =
((DOMImplementationLS&)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS,
0);


Using this code, I receive a segmentation fault in ReaderMgr where it
attempts to call src.makeStream().

Do I need to prepare my memIS object some other way so that it will properly
provide a BinInputStream object to the functions farther down the line?

Thanks,

Dan

On Mon, May 12, 2008 at 12:48 PM, Sahoglu, Ozgur <Oz...@intuit.com>
wrote:

>
> Hi Dan,
>
> Parsing a file is no different than parsing a memory buffer (or any
> other input source). They all use BinInputStream internally if you look
> at the Xerces-C++ implementation. All you need to do is create the
> MemBufInputSource and pass it to parser's parse() method (see the API
> doc
> http://xerces.apache.org/xerces-c/apiDocs/classAbstractDOMParser.html#b6
> fbd6cdf84cce77db1c780017d107dd<http://xerces.apache.org/xerces-c/apiDocs/classAbstractDOMParser.html#b6fbd6cdf84cce77db1c780017d107dd>
> ).
>
> DOM parser's parse() method is overloaded to accept a system id (a file
> path or URL) or an InputSource, which can be a LocalFileInputSource, a
> URLInputSource, a StdInInputSource, a Wrapper4DOMInputSource, or a
> MemBufInputSource (see
> http://xerces.apache.org/xerces-c/apiDocs/classInputSource.html).
>
> Cheers,
>
>
> -Ozgur Sahoglu
>
> -----Original Message-----
> From: Dan Arcari [mailto:danarcari@gmail.com]
> Sent: Monday, May 12, 2008 11:05 AM
> To: c-users@xerces.apache.org
> Subject: Using MemBufInputSource with DOM parser
>
> Hello,
>
> We have a library written on top of Xerces-c which uses DOM parsing of
> file-based XML. We would like to be able to send a MemBufInputSource (or
> derivation) via our library to xerces so we can parse XML which does not
> reside in a file. Is this possible, and could anyone share some examples
> or
> advice on how to go about this?
>
> Thanks
>

RE: Using MemBufInputSource with DOM parser

Posted by "Sahoglu, Ozgur" <Oz...@intuit.com>.
Hi Dan,

Parsing a file is no different than parsing a memory buffer (or any
other input source). They all use BinInputStream internally if you look
at the Xerces-C++ implementation. All you need to do is create the
MemBufInputSource and pass it to parser's parse() method (see the API
doc
http://xerces.apache.org/xerces-c/apiDocs/classAbstractDOMParser.html#b6
fbd6cdf84cce77db1c780017d107dd). 

DOM parser's parse() method is overloaded to accept a system id (a file
path or URL) or an InputSource, which can be a LocalFileInputSource, a
URLInputSource, a StdInInputSource, a Wrapper4DOMInputSource, or a
MemBufInputSource (see
http://xerces.apache.org/xerces-c/apiDocs/classInputSource.html). 

Cheers,


-Ozgur Sahoglu

-----Original Message-----
From: Dan Arcari [mailto:danarcari@gmail.com] 
Sent: Monday, May 12, 2008 11:05 AM
To: c-users@xerces.apache.org
Subject: Using MemBufInputSource with DOM parser

Hello,

We have a library written on top of Xerces-c which uses DOM parsing of
file-based XML. We would like to be able to send a MemBufInputSource (or
derivation) via our library to xerces so we can parse XML which does not
reside in a file. Is this possible, and could anyone share some examples
or
advice on how to go about this?

Thanks

RE: Using MemBufInputSource with DOM parser

Posted by Jesse Pelton <js...@PKC.com>.
Take a look at the MemParse sample, which uses a MemBufInputSource to
parse an in-memory document. 

-----Original Message-----
From: Dan Arcari [mailto:danarcari@gmail.com] 
Sent: Monday, May 12, 2008 2:05 PM
To: c-users@xerces.apache.org
Subject: Using MemBufInputSource with DOM parser

Hello,

We have a library written on top of Xerces-c which uses DOM parsing of
file-based XML. We would like to be able to send a MemBufInputSource (or
derivation) via our library to xerces so we can parse XML which does not
reside in a file. Is this possible, and could anyone share some examples
or
advice on how to go about this?

Thanks