C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Xerces-C | istream nach InputSource

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Christoph Happich
Guest





PostPosted: Thu Jul 17, 2003 5:23 pm    Post subject: Xerces-C | istream nach InputSource Reply with quote



Hallo NG,

ich hoffe das ist die richtige NG, könnte ja auch gut nach XML passen.
Eigendlich geht es aber um C++ bzw. Xerces-C.

Der DOM-Parser/Builder von Xerces kann sowohl eine Datei, als auch ein
"InputSource" parsen. Leider kommen meine XML-Daten über einen istream.
Die Frage ist also: wie bekomme ich eine InputSource aus einem istream?

Vielen Dank schonmal, Christoph

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
Back to top
Steffen Cersowsky
Guest





PostPosted: Fri Jul 18, 2003 7:53 am    Post subject: Re: Xerces-C | istream nach InputSource Reply with quote



Christoph Happich wrote:

[...]

Quote:
Der DOM-Parser/Builder von Xerces kann sowohl eine Datei, als auch ein
"InputSource" parsen. Leider kommen meine XML-Daten über einen istream.
Die Frage ist also: wie bekomme ich eine InputSource aus einem istream?

Vielen Dank schonmal, Christoph

Hallo Christoph,

hast Du mal das Interface der InputSource angeschaut? Die Hauptfunktion
liefert einfach einen BinInputStream. Und dieser besteht im Wesentlichen
nur aus einer Funktion, welche irgendwie Rohbytes einliest.
Es bleibt also nur noch die Frage: Wie kann ich aus einem std::istream
unformatiert lesen? Dieses Problem laesst sich mit dem Puffer des
istreams loesen. Meine Loesung sah letztlich so aus:

class InputSrc : public XERCES_CPP_NAMESPACE_QUALIFIER InputSource
{ public:
InputSrc(std::streambuf &);
virtual XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream* makeStream() const;
private:
InputSrc(InputSrc const &);
InputSrc &operator=(InputSrc const &);
std::streambuf &m_Strm;

class Stream : public XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream
{ public:
Stream(std::streambuf &);
virtual unsigned curPos() const;
virtual unsigned readBytes(XMLByte* const, unsigned const);
private:
Stream(Stream const &);
Stream &operator=(Stream const &);
std::streambuf &m_Strm;
unsigned m_Pos;
};
};

InputSrc::Stream::Stream(std::streambuf &strm):m_Strm(strm), m_Pos(0)
{}
unsigned InputSrc::Stream::curPos() const
{ return m_Pos;
}
unsigned InputSrc::Stream::readBytes(XMLByte * const buff, unsigned const len)
{ unsigned n=m_Strm.sgetn(reinterpret_cast<char * const>(buff), len);
m_Pos+=n;
return n;
}

InputSrc::InputSrc(std::streambuf &strm):m_Strm(strm)
{}
XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream* InputSrc::makeStream() const
{ return new Stream(m_Strm);
}

// std::istream strm;
// InputSrc is(*(strm.rdbuf()));


Tschuess,
Steffen.

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Werner Salomon
Guest





PostPosted: Fri Jul 18, 2003 11:41 am    Post subject: Re: Xerces-C | istream nach InputSource Reply with quote



Christoph Happich <christoph.happich (AT) uni-bielefeld (DOT) de> wrote

Quote:
Hallo NG,

ich hoffe das ist die richtige NG, könnte ja auch gut nach XML passen.
Eigendlich geht es aber um C++ bzw. Xerces-C.

Der DOM-Parser/Builder von Xerces kann sowohl eine Datei, als auch ein
"InputSource" parsen. Leider kommen meine XML-Daten über einen istream.
Die Frage ist also: wie bekomme ich eine InputSource aus einem istream?

Hallo Christoph,

vor dem gleichen Problem stand ich auch (mit ostream). Ich denke, dass
ist einer der Schwachpunkte in der sonst guten Bibliothek.

Also die (wahrscheinliche) Lösung ist nach meiner Einschätzung:

Du benötigst einen konkrete InputSource (neben den existierenden von
LocalFileInputSource bis Wrapper4DOMInputSource), die in ihrer Methode
makeStream einen konkreten BinInputStream liefert, dessen Methoden
curPos und readBytes zur Verfügung gestellt werden müssen.

Also code-technisch etwa so:

class IstreamBinInput : public xercesc::BinInputStream {
public:
explicit IstreamBinInput( std::istream& in )
: BinInputStream()
, m_istream( in ) {}

// die beiden Methoden müssen mit Zugriffen auf
// m_istream gefüllt werden
// -> z.B.: m_istream.rdbuf().pubseekoff(), m_istream.read() ..
// .. schau vielleicht mal in anderen konkreten Derivate rein
virtual unsigned int curPos();
virtual unsigned int readBytes( XMLByte* const toFill,
const unsigned int maxToRead );
// ...
private:
std::istream& m_istream;
// ...


class IstreamInputSource : public xercesc::InputSource {
public:
explicit IstreamInputSource( std::istream& in )
: xercesc::InputSource()
, m_istream( in ) {}

virtual xercesc::BinInputStream makeStream() const {
return new IstreamBinInput( m_istream );
}
// ...
// ob & was hier sonst noch zu tun ist, weis ich nicht!
private:
std::istream& m_istream;
// ...

Im Prinzip sollte es so gehen. Ich habe es bisher nur für die Ausgabe
(ostream) d.h.
class OstreamFormatTarget : public xercesc::XMLFormatTarget {
// ..
private:
std::ostream& m_out;
// ...
wirklich realisiert. Da hat es sofort funktioniert.

Noch 'ne Bemerkung zu dem 'wahrscheinlich' s.o. In der Xerces Library
sind noch mehrere Klassen, die 'auch so was ähnliches' machen. Z.B.:
DOMInputSource nebst Wrapper4InputSource, die nicht (!) von
InputSource abgeleitet sind, dafür aber vom DOMBuilder (!?) genutzt
werden. Ich blicke nicht wirklich durch, wie das alles zusammenspielt.

Gruß
Werner

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group