Vaucanson  1.4.1
tools.hxx
1 // tools.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2007, 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 
18 #ifndef VCSN_XML_TOOLS_HXX
19 # define VCSN_XML_TOOLS_HXX
20 
21 # include <vaucanson/xml/strings.hh>
22 
23 namespace vcsn
24 {
25  namespace xml
26  {
27  namespace tools
28  {
33  inline
34  bool
35  has_attribute (const xercesc::Attributes& attrs,
36  const char* key,
37  const XMLCh* const uri)
38  {
39  return (get_attribute(attrs, key, uri) != 0);
40  }
41 
42  inline
43  bool
44  has_attribute (const xercesc::Attributes& attrs,
45  const XMLCh* xkey,
46  const XMLCh* const uri)
47  {
48  return (get_attribute(attrs, xkey, uri) != 0);
49  }
50 
51  inline
52  const XMLCh*
53  get_attribute (const xercesc::Attributes& attrs,
54  const char* key,
55  const XMLCh* const uri)
56  {
57  XMLCh* xkey = transcode(key);
58  const XMLCh* tmp = attrs.getValue(uri, xkey);
59  xercesc::XMLString::release(&xkey);
60  return tmp;
61  }
62 
63  inline
64  const XMLCh*
65  get_attribute (const xercesc::Attributes& attrs,
66  const XMLCh* xkey,
67  const XMLCh* const uri)
68  {
69  const XMLCh* tmp = attrs.getValue(uri, xkey);
70  return tmp;
71  }
72 
76  void
77  set_attribute (xercesc::DOMElement* e,
78  const std::string& k, const std::string& v)
79  {
80  if (v != "")
81  e->setAttribute (transcode(k), transcode(v));
82  }
86  xercesc::DOMElement*
87  create_element(xercesc::DOMDocument* doc,
88  const std::string& e)
89  {
90  return doc->createElementNS(transcode(VCSN_XMLNS), transcode(e));
91  }
92  } // !tools
93  } // !xml
94 } // !vcsn
95 
96 #endif // !VCSN_XML_TOOLS_HXX