Różnice między wybraną wersją a wersją aktualną.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
xerces_dom [2008/04/15 01:03] kmioduszewski |
xerces_dom [2008/04/15 01:18] kmioduszewski |
||
---|---|---|---|
Linia 139: | Linia 139: | ||
</code> | </code> | ||
+ | |||
+ | |||
Linia 183: | Linia 185: | ||
<!ELEMENT body (#PCDATA)> | <!ELEMENT body (#PCDATA)> | ||
</code> | </code> | ||
- | Klasy pomocnicze: | + | Klasy pomocnicze ''support.h'': |
<code cpp> | <code cpp> | ||
- | #include<string> | + | #include <string> |
- | #include<xercesc/util/XMLString.hpp> | + | #include <iostream> |
+ | #include <xercesc/util/XMLString.hpp> | ||
+ | #include <xercesc/sax/HandlerBase.hpp> | ||
+ | |||
//klasa pomocnicza ułatwiająca współpracę z XMLCh* | //klasa pomocnicza ułatwiająca współpracę z XMLCh* | ||
class UniString { | class UniString { | ||
Linia 196: | Linia 200: | ||
xmlString(xercesc::XMLString::replicate(str)) | xmlString(xercesc::XMLString::replicate(str)) | ||
{} | {} | ||
- | + | ||
UniString(const char* const str) | UniString(const char* const str) | ||
: | : | ||
Linia 202: | Linia 206: | ||
xmlString(xercesc::XMLString::transcode(str)) | xmlString(xercesc::XMLString::transcode(str)) | ||
{} | {} | ||
+ | |||
UniString(const std::string& str) | UniString(const std::string& str) | ||
: | : | ||
Linia 208: | Linia 212: | ||
xmlString(xercesc::XMLString::transcode(str.c_str())) | xmlString(xercesc::XMLString::transcode(str.c_str())) | ||
{} | {} | ||
- | + | ||
~UniString() | ~UniString() | ||
{ | { | ||
Linia 214: | Linia 218: | ||
xercesc::XMLString::release(&xmlString); | xercesc::XMLString::release(&xmlString); | ||
} | } | ||
+ | |||
const char* toCString() { return cString; } | const char* toCString() { return cString; } | ||
const XMLCh* toXMLString() { return xmlString; } | const XMLCh* toXMLString() { return xmlString; } | ||
- | + | ||
std::ostream& print(std::ostream& s) const | std::ostream& print(std::ostream& s) const | ||
{ | { | ||
Linia 223: | Linia 227: | ||
return(s); | return(s); | ||
} | } | ||
+ | |||
private : | private : | ||
char* cString; | char* cString; | ||
XMLCh* xmlString; | XMLCh* xmlString; | ||
+ | |||
}; | }; | ||
- | + | ||
- | std::ostream& operator<<( std::ostream& s, const UniString& str ) { return s << str.print(); } | + | std::ostream& operator<<( std::ostream& s, const UniString& str ) { return str.print(s); } |
+ | |||
//klasa pomocnicza przechowująca nazwy tagów oraz atrybutów | //klasa pomocnicza przechowująca nazwy tagów oraz atrybutów | ||
class docNames { | class docNames { | ||
Linia 244: | Linia 248: | ||
const UniString ATTR_DATE; | const UniString ATTR_DATE; | ||
- | TagNames() | + | docNames() |
: | : | ||
TAG_NOTES("notes"), | TAG_NOTES("notes"), | ||
Linia 255: | Linia 259: | ||
ATTR_DATE("date") | ATTR_DATE("date") | ||
{} | {} | ||
+ | }; | ||
+ | |||
+ | class myErrorHandler : xercesc::HandlerBase { | ||
+ | void warning( const xercesc::SAXParseException& e ) { | ||
+ | std::cout << "warning: " << UniString(e.getMessage()) | ||
+ | << " | line: " << e.getLineNumber() << std::endl; | ||
+ | } | ||
+ | void error( const xercesc::SAXParseException& e ) { | ||
+ | std::cout << "error: " << UniString(e.getMessage()) | ||
+ | << " | line: " << e.getLineNumber() << std::endl; | ||
+ | } | ||
+ | void fatalError( const xercesc::SAXParseException& e ) { | ||
+ | std::cout << "fatalError: " << UniString(e.getMessage()) | ||
+ | << " | line: " <<e.getLineNumber() << std::endl; | ||
+ | } | ||
+ | void resetErrors() {} | ||
}; | }; | ||
</code> | </code> |