Discussion:
Using MemBufInputSource with DOM parser
Dan Arcari
2008-05-12 18:05:18 UTC
Permalink
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
Jesse Pelton
2008-05-12 19:22:49 UTC
Permalink
Take a look at the MemParse sample, which uses a MemBufInputSource to
parse an in-memory document.

-----Original Message-----
From: Dan Arcari [mailto:***@gmail.com]
Sent: Monday, May 12, 2008 2:05 PM
To: c-***@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
Sahoglu, Ozgur
2008-05-12 19:48:11 UTC
Permalink
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:***@gmail.com]
Sent: Monday, May 12, 2008 11:05 AM
To: c-***@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
Dan Arcari
2008-05-12 23:42:08 UTC
Permalink
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
Post by Sahoglu, Ozgur
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-----
Sent: Monday, May 12, 2008 11:05 AM
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
Sahoglu, Ozgur
2008-05-12 23:59:30 UTC
Permalink
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:***@gmail.com]
Sent: Monday, May 12, 2008 4:42 PM
To: c-***@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
Post by Sahoglu, Ozgur
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>
Post by Sahoglu, Ozgur
).
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-----
Sent: Monday, May 12, 2008 11:05 AM
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
Alberto Massari
2008-05-13 00:17:41 UTC
Permalink
Wrapper4InputSource wrap(memIS, false);
mParser->parse(wrap);


Alberto
Post by Sahoglu, Ozgur
Dan,
Remove the cast in the parse() method. MemBufInputSource is-a
MemBufInputSource* memIS = new MemBufInputSource((const XMLByte
*)someXML, strlen(someXML), "test", false);
mParser->parse(*memIS);
Cheers,
-Ozgur Sahoglu
-----Original Message-----
Sent: Monday, May 12, 2008 4:42 PM
Subject: Re: Using MemBufInputSource with DOM parser
Thanks Ozgur.
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 =
((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
Post by Sahoglu, Ozgur
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
Post by Sahoglu, Ozgur
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>
Post by Sahoglu, Ozgur
).
DOM parser's parse() method is overloaded to accept a system id (a
file
Post by Sahoglu, Ozgur
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-----
Sent: Monday, May 12, 2008 11:05 AM
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
Post by Sahoglu, Ozgur
derivation) via our library to xerces so we can parse XML which does
not
Post by Sahoglu, Ozgur
reside in a file. Is this possible, and could anyone share some
examples
Post by Sahoglu, Ozgur
or
advice on how to go about this?
Thanks
Dan Arcari
2008-05-13 00:44:30 UTC
Permalink
Thanks Alberto. This was successful!
Post by Alberto Massari
Wrapper4InputSource wrap(memIS, false);
mParser->parse(wrap);
Alberto
Post by Sahoglu, Ozgur
Dan,
Remove the cast in the parse() method. MemBufInputSource is-a
MemBufInputSource* memIS = new MemBufInputSource((const XMLByte
*)someXML, strlen(someXML), "test", false);
mParser->parse(*memIS);
Cheers,
-Ozgur Sahoglu
-----Original Message-----
4:42 PM
Subject: Re: Using MemBufInputSource with DOM parser
Thanks Ozgur.
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 =
((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
Post by Sahoglu, Ozgur
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
Post by Sahoglu, Ozgur
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>
Post by Sahoglu, Ozgur
).
DOM parser's parse() method is overloaded to accept a system id (a
file
Post by Sahoglu, Ozgur
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-----
Sent: Monday, May 12, 2008 11:05 AM
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
Post by Sahoglu, Ozgur
derivation) via our library to xerces so we can parse XML which does
not
Post by Sahoglu, Ozgur
reside in a file. Is this possible, and could anyone share some
examples
Post by Sahoglu, Ozgur
or
advice on how to go about this?
Thanks
Loading...