[xsd-users] Problems with generated schema
ope
ope-devel at gmx.de
Mon Jul 23 15:00:38 EDT 2007
Hi Boris,
> You get these errors because XML Schema validation is enabled by
> default and the parser cannot find the schema since none is
> specified in the instance or elsewhere. You have three options:
>
> 1. Disable validation.
>
> 2. Add schemaLocation attributes to your XML documents.
>
> 3. Programmatically specify the schema location.
>
> These options are discussed in more detail in Section 2, "Validaion
> and Parsing" of the FAQ:
>
> http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/faq/#2
I did try the 3rd Option without success.
---8<---
class metalink_parser
{
private:
typedef std::vector<std::string> metalink_files_t;
public:
metalink_parser();
metalink_parser(const std::string& file);
public:
void append(const std::string& file);
void load();
private:
metalink_files_t m_metalink_files;
std::auto_ptr<metalink::metalinkType> m_metalink;
xml_schema::properties m_metalink_props;
};
---8<---
metalink_parser::metalink_parser() {
m_metalink_props.schema_location (
"http://www.metalinker.org/",
"file:///home/ope/Projects/cpp/test/schema/metalink.xsd");
m_metalink_props.no_namespace_schema_location (
"file:///home/ope/Projects/cpp/test/schema/metalink.xsd");
}
metalink_parser::metalink_parser(const std::string& file){
m_metalink_files.push_back(file);
}
void metalink_parser::append(const std::string& file) {
m_metalink_files.push_back(file);
}
void metalink_parser::load() {
assert(m_metalink.get() == 0);
// TODO: a lot of checks
const std::string metalink_file = m_metalink_files.front();
try {
// take ownership
//m_metalink = metalink::metalink(metalink_file,
xml_schema::flags::dont_validate);
m_metalink = metalink::metalink(metalink_file, 0, m_metalink_props);
metalink::filesType::file::const_iterator
first(m_metalink->files().file().begin());
metalink::filesType::file::const_iterator
last(m_metalink->files().file().begin());
for (; first != last; ++first) {
cout << *first;
}
}
catch (const xml_schema::exception& e) {
cerr << e << endl;
}
}
--->8---
If I disable validation (1st Option) no output is performed.
As you may see, these are my first steps in Xerces and XSD.
Thanks
Olaf
More information about the xsd-users
mailing list