xml 解析の分野ではまったくの初心者でしたが、xsd
有効なファイルを作成c++
し、コンパイルとリンクを正常に行うことができましたが、コンパイラはインスタンス化を最適化 (?) してしまいました。そこで、ステップ 1 から始めて、CodeSynthesis でhello world xml の例を試します。しかし、それは失敗します:
[wally@lenovotower xml]$ make hello
xsdcxx cxx-tree hello.xsd
g++ -c -o helloschema.o hello.cxx
g++ -g -o hello -lxerces-c helloschema.o hello.c++
[wally@lenovotower xml]$ ./hello
hello.xml:2:8 error: no declaration found for element 'hello'
hello.xml:4:13 error: no declaration found for element 'greeting'
hello.xml:6:9 error: no declaration found for element 'name'
hello.xml:7:9 error: no declaration found for element 'name'
hello.xml:8:9 error: no declaration found for element 'name'
こんにちは.c++:
#include <iostream>
#include <stdio.h>
#include "hello.hxx"
using namespace std;
int main (void)
{
try {
auto_ptr<hello_t> h (hello ("hello.xml"));
for (hello_t::name_const_iterator i (h->name ().begin());
i != h->name().end();
++i)
cout << h->greeting () << ", " << *i << "!" << endl;
}
catch (const xml_schema::exception& e)
{
cerr << e << endl;
return 1;
}
return 0;
}
こんにちは.xml:
<?xml version="1.0"?>
<hello>
<greeting>Hello</greeting>
<name>sun</name>
<name>moon</name>
<name>world</name>
</hello>
こんにちは.xsd:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="hello_t">
<xs:sequence>
<xs:element name="greeting" type="xs:string"/>
<xs:element name="name" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="hello" type="hello_t"/>
</xs:schema>
これはまさにその通りだと思いますが、コマンドは文書化されているとおりには機能しません。xsdcxx
私は正しいことをしているように見えることを発見しました( xsd
C#またはvb.net出力を生成するのとは異なります)。
[wally@lenovotower xml]$ xsdcxx --version
CodeSynthesis XSD XML Schema to C++ compiler 3.3.0
Copyright (C) 2005-2010 Code Synthesis Tools CC
また、-I
(dir) を含めず、問題なくコンパイルされます。どういうわけか間違ったインクルード ファイルを使用している可能性がありますか?
私は何を間違っていますか?たぶんxsd
適切なツールではありませんか?