All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ReadXSD.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/xsd/ReadXSD.cpp
22 
23  \brief Functions for reading an XSD.
24 */
25 
26 // TerraLib
27 #include "ReadXSD.h" // tip: keep this order of include
28 #include "../xml/ReaderFactory.h"
29 #include "Exception.h"
30 #include "Schema.h"
31 
32 // STL
33 #include <cassert>
34 #include <memory>
35 
36 #if TE_XSD_BUILD_WITH_XML_PARSER
37 
38 te::xsd::Schema* te::xsd::Read(const std::string& file_name)
39 {
40  std::auto_ptr<te::xml::Reader> xml_reader(te::xml::ReaderFactory::make());
41 
42  xml_reader->setValidationScheme(false);
43 
44  xml_reader->read(file_name);
45 
46  assert(xml_reader->getNodeType() == te::xml::START_DOCUMENT);
47 
48 // read schema element
49  xml_reader->next();
50  assert(xml_reader->getNodeType() == te::xml::START_ELEMENT);
51  assert(xml_reader->getElementLocalName() == "schema");
52 
53  std::auto_ptr<te::xsd::Schema> my_schema(new te::xsd::Schema(0));
54 
55  std::size_t n_namespaces = xml_reader->getNumberOfNamespaces();
56 
57 // get namespaces
58  for(std::size_t i = 0; i != n_namespaces; ++i)
59  {
60  std::pair<std::string, std::string> ns;
61 
62  xml_reader->getNamespace(i, ns);
63 
64  my_schema->getNamespaces().insert(boost::bimap<std::string, std::string>::value_type(ns.first, ns.second));
65  }
66 
67 // get schema attributes
68  {
69  std::size_t pos = xml_reader->getAttrPosition("id");
70 
71  if(pos != std::string::npos)
72  my_schema->setId(new std::string(xml_reader->getAttr(pos)));
73  }
74 
75  {
76  std::size_t pos = xml_reader->getAttrPosition("attributeFormDefault");
77 
78  if(pos != std::string::npos)
79  my_schema->setAttributeFormDefault(xml_reader->getAttr(pos) == "qualified" ? Qualified : Unqualified);
80  }
81 
82  {
83  std::size_t pos = xml_reader->getAttrPosition("elementFormDefault");
84 
85  if(pos != std::string::npos)
86  my_schema->setElementFormDefault(xml_reader->getAttr(pos) == "qualified" ? Qualified : Unqualified);
87  }
88 
89  //{
90  // std::size_t pos = xml_reader->getAttrPosition("blockDefault");
91 
92  // if(pos != std::string::npos)
93  // my_schema->setId(new std::string(xml_reader->getAttr(pos)));
94  //}
95 
96  //{
97  // std::size_t pos = xml_reader->getAttrPosition("finalDefault");
98 
99  // if(pos != std::string::npos)
100  // my_schema->setId(new std::string(xml_reader->getAttr(pos)));
101  //}
102 
103  {
104  std::size_t pos = xml_reader->getAttrPosition("targetNamespace");
105 
106  if(pos != std::string::npos)
107  my_schema->setTargetNamespace(xml_reader->getAttr(pos));
108  }
109 
110  {
111  std::size_t pos = xml_reader->getAttrPosition("version");
112 
113  if(pos != std::string::npos)
114  my_schema->setVersion(xml_reader->getAttr(pos));
115  }
116 
117  return 0;
118 }
119 
120 #endif // TE_XSD_BUILD_WITH_XML_PARSER
An exception class for the XSD module.
A class that models a XML schema (XSD).
Definition: Schema.h:63
A class that models an XML Schema (XSD).
static te::xml::Reader * make()
It creates a new XML reader using the dafault implementation.
TEXSDEXPORT Schema * Read(const std::string &file_name)
Definition: ReadXSD.cpp:38
It indicates that the attribute attribute must be qualified with the namespace prefix and the no-colo...
Definition: Enums.h:114
It indicates that the attribute attribute is not required to be qualified with the namespace prefix a...
Definition: Enums.h:115
Functions for reading an XSD.