blob: 8f3454e7d2c5c07e4b312fb7cf9b9a9444784a71 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// $Id$
#include "XML_Helper.h"
#include "ace/Log_Msg.h"
#include "xercesc/dom/DOM.hpp"
#include "xercesc/parsers/XercesDOMParser.hpp"
#include "XML/XercesString.h"
namespace Test
{
namespace XML
{
Helper::Helper (CIAO::XML::XML_Error_Handler &eh)
: impl_ (0)
, parser_ (0)
, e_handler_ (eh)
{
this->init_parser ();
}
Helper::~Helper (void)
{
this->terminate_parser ();
}
void
Helper::init_parser (void)
{
// Initialize the Xerces run-time
XERCES_CPP_NAMESPACE::XMLPlatformUtils::Initialize();
// Instantiate the DOM parser.
static const XMLCh gLS[] = { XERCES_CPP_NAMESPACE::chLatin_L,
XERCES_CPP_NAMESPACE::chLatin_S,
XERCES_CPP_NAMESPACE::chNull };
// Get an implementation of the Load-Store (LS) interface
// and cache it for later use
impl_ =
XERCES_CPP_NAMESPACE::DOMImplementationRegistry::getDOMImplementation(gLS);
}
int
Helper::validate_dom (const ACE_TCHAR *url)
{
if (url == 0)
return 0;
try
{
if (this->parser_ == 0)
this->parser_ = new XERCES_CPP_NAMESPACE::XercesDOMParser ();
// Discard comment nodes in the document
this->parser_->setCreateCommentNodes (false);
// Do not create EntityReference nodes in the DOM tree. No
// EntityReference nodes will be created, only the nodes
// corresponding to their fully expanded sustitution text will be
// created.
this->parser_->setCreateEntityReferenceNodes (false);
// Perform Validation
this->parser_->setValidationScheme (
XERCES_CPP_NAMESPACE::AbstractDOMParser::Val_Always);
// Do not include ignorable whitespace in the DOM tree.
this->parser_->setIncludeIgnorableWhitespace (false);
// Enable full schema constraint checking, including checking which
// may be time-consuming or memory intensive. Currently, particle
// unique attribution constraint checking and particle derivation
// restriction checking are controlled by this option.
this->parser_->setValidationSchemaFullChecking (true);
this->parser_->setErrorHandler (&e_handler_);
this->parser_->parse (ACE_TEXT_ALWAYS_CHAR (url));
if (e_handler_.getErrors ())
return 1;
return 0;
}
catch (...)
{
ACE_DEBUG ((LM_DEBUG,
"(%P|%t) Caught an unknown exception\n"));
throw;
}
return 0;
}
void
Helper::terminate_parser (void)
{
XERCES_CPP_NAMESPACE::XMLPlatformUtils::Terminate ();
}
}
}
|