Vaucanson  1.4.1
ios.hxx
1 // ios.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2004, 2005, 2006, 2008, 2009 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_XML_INTERNAL_IOS_HXX
18 # define VCSN_XML_INTERNAL_IOS_HXX
19 
21 
22 XERCES_CPP_NAMESPACE_BEGIN
23 
24 template<class Ostream>
25 void
26 XMLPARSER_EXPORT
27 XMLXercesStream<Ostream>::writeChars(const XMLByte* const toWrite,
28  const XMLSize_t,
29  XMLFormatter* const)
30 {
31  os_ << toWrite;
32 }
33 
34 XERCES_CPP_NAMESPACE_END
35 
36 namespace vcsn
37 {
38  namespace xml
39  {
40  inline
41  XMLSize_t
42  BinCxxInputStream::readBytes(XMLByte *const toFill,
43  const XMLSize_t maxToRead)
44  {
45  // istream::readsome does not seem to work on SunOS
46  unsigned s = _in->rdbuf()->sgetn((char *)toFill, maxToRead);
47  _pos += s;
48  return s;
49  }
50 
51  inline
52  XERCES_FILEPOS
53  BinCxxInputStream::curPos() const
54  {
55  return _pos;
56  }
57 
58  inline
59  BinCxxInputStream*
60  CxxInputSource::makeStream() const
61  {
62  return new BinCxxInputStream(_in);
63  }
64 
65  void
66  print_xml(std::ostream& out,
67  xercesc::DOMImplementation* impl,
68  xercesc::DOMElement* root)
69  {
70  using namespace xercesc;
71 
73 
74 # if XERCES_VERSION_MAJOR == 2
75  DOMWriter* writer = impl->createDOMWriter();
76 
77  if (writer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
78  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
79 
80  writer->writeNode(outstream, *root);
81 # elif XERCES_VERSION_MAJOR > 2
82  DOMLSSerializer* writer = impl->createLSSerializer();
83  DOMLSOutput *target = impl->createLSOutput();
84  target->setByteStream(outstream);
85  DOMConfiguration *config = writer->getDomConfig();
86 
87  if (config->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
88  config->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
89 
90  writer->write(root, target);
91 # else
92 # error "Unsupported Xerces-C++ major version (too old)."
93 # endif
94 
95  writer->release();
96 
97  delete outstream;
98  }
99 
100  } // ! xml
101 
102 } // ! vcsn
103 
104 #endif // ! VCSN_XML_INTERNAL_IOS_HXX