1: // cexer
2: #include "./include/XML/xmlfile.h"
3: #include "./include/XML/xmlelement.h"
4: #include "./include/XML/xmldeclaration.h"
5: #include "./include/XML/xmlunknown.h"
6: #include "./include/XML/xmlcomment.h"
7: #include "./include/XML/xmltext.h"
8: #include "./include/XML/xmlattribute.h"
9:
10: using namespace cexer;
11: using namespace cexer::xml;
12:
13:
14: // c++ std
15: #include <iostream>
16: using namespace std;
17:
18:
19: int wmain( int argc,WCHAR** argv )
20: {
21: wcout.imbue( std::locale("chs") );
22:
23: XmlFile document( L"./XMLs/utf16le_ns.xml" );
24: if ( !document.load() )
25: {
26: wcout<<L"解析失败"<<endl;
27: return 0;
28: }
29:
30: XmlElement* root = document.element();
31: if ( !root )
32: {
33: wcout<<L"没有找到根结点"<<endl;
34: return 0;
35: }
36:
37: wcout<<root->name()<<endl;
38:
39:
40: XmlNode* firstChild = root->firstChild();
41: if ( !firstChild )
42: {
43: wcout<<L"没有子结点"<<endl;
44: return 0;
45: }
46:
47: XmlDeclaration* declar = xml_cast<XmlDeclaration*>( firstChild );
48: if ( !declar )
49: {
50: wcout<<L"第一个子结点不是声明"<<endl;
51: }
52: else
53: {
54: wcout<<L"第一个节点是声明"<<endl;
55: wcout<<L"version = "<<declar->version()<<endl;
56: wcout<<L"encoding = "<<declar->encoding()<<endl;
57: wcout<<L"standalone = "<<declar->standalone()<<endl;
58: }
59:
60: XmlComment* comment = xml_cast<XmlComment*>( firstChild->next() );
61: if ( !comment )
62: {
63: wcout<<L"第二个子结点不是注释"<<endl;
64: }
65: else
66: {
67: wcout<<L"第二个结点是注释:"<<comment->value()<<endl;
68: }
69:
70: XmlElement* window = root->element( L"window" );
71: if ( !window )
72: {
73: wcout<<L"没有找到window元素结点"<<endl;
74: return 0;
75: }
76: wcout<<window->attributeValue( L"text" )<<endl;
77:
78:
79: XmlElement* nextWindow = window->nextElement( L"window" );
80: if ( !nextWindow )
81: {
82: wcout<<L"没有找到后面的window元素结点"<<endl;
83: }
84: else
85: {
86: wcout<<L"后面还有一个window元素结点 ";
87: wcout<<nextWindow->attributeValue(_T("name"))<<endl;
88: }
89:
90: XmlElement* panel = window->element( L"panel" );
91: if ( panel )
92: {
93: wcout<<panel->attributeValue( L"caption" )<<endl;
94: }
95:
96: window->setAttribute( L"styleAdd",L"WS_VISIBLE" );
97: window->setAttribute( L"styleRemove",L"\";<>=&\"" );
98:
99: if ( !document.save( L"./XMLs/modified/utf16le_ns.xml" ) )
100: {
101: wcout<<L"保存失败"<<endl;
102: }
103:
104: return 0;
105: }