72 const XML_Char* context,
76 void* user_data = XML_GetUserData (
parser);
84 std::cout <<
"ExpatCoreParser::register_external_entity> name=" <<
name
85 <<
" file_name=" <<
file_name << std::endl;
94 std::cout <<
"ExpatCoreParser::register_text_entity> name=" <<
name
103 const XML_Char* entityName,
104 int is_parameter_entity,
105 const XML_Char*
value,
107 const XML_Char*
base,
109 const XML_Char* publicId,
113 if (!publicId) publicId =
"none";
114 std::string temp =
"none";
116 char*
t = (
char*)
malloc (value_length + 1);
117 strncpy (
t,
value, value_length);
119 temp = (
const char*)
t;
124 std::cout <<
"ExpatCoreParser::entity[" << 0 <<
"]> " << entityName;
125 std::cout <<
" is_parameter=" << is_parameter_entity;
126 std::cout <<
" value=[" << temp <<
"]";
127 std::cout <<
" base=[" <<
base <<
"]";
128 std::cout <<
" systemId=[" <<
systemId <<
"]";
129 std::cout <<
" publicId=[" << publicId <<
"]";
130 std::cout << std::endl;
134 std::unique_ptr<CoreParser::DOMNode>
136 return std::move(
m_top);
148 std::map <std::string, std::string>
a;
150 m_top = std::make_unique<CoreParser::DOMNode> ();
155 std::cout <<
"ExpatCoreParser::do_start> el=" <<
el <<
" top=" <<
m_top.get() <<
" last=" <<
m_last <<
" node=" <<
node << std::endl;
158 for (
i = 0; attr[
i];
i += 2) {
159 const char*
name = attr[
i];
160 const char*
value = attr[
i+1];
168 std::cout <<
"ExpatCoreParser::do_end> el=" <<
el << std::endl;
175 if (len == 0)
return;
176 while ((len > 0) && (
s[len-1] ==
'\n')) len--;
177 if (len == 0)
return;
178 char* temp = (
char*)
malloc (len + 1);
179 strncpy (temp,
s, len);
182 std::cout <<
"ExpatCoreParser::do_char_data> [" << temp <<
"]" << std::endl;
189 if (len == 0)
return;
190 while ((len > 0) && (
s[len-1] ==
'\n')) len--;
191 if (len == 0)
return;
192 char* temp = (
char*)
malloc (len + 1);
193 strncpy (temp,
s, len);
196 std::cout <<
"ExpatCoreParser::do_default_handler> [" << temp <<
"]" << std::endl;
204 m_top = std::make_unique<CoreParser::DOMNode> ();
209 std::cout <<
"ExpatCoreParser::do_comment> s=" <<
s <<
" top=" <<
m_top.get() <<
" last=" <<
m_last <<
" node=" <<
node << std::endl;
220 std::cout <<
"ExpatCoreParser::generic_parse> file_name=" <<
file_name <<
" prefix=" <<
m_prefix << std::endl;
224 docfd = fopen (temp_name.c_str (),
"r");
227 docfd = fopen (temp_name.c_str (),
"r");
231 const char* xmlpathenv =
::getenv (
"XMLPATH");
232 if (xmlpathenv == 0)
return (0);
233 std::string xmlpath = xmlpathenv;
234 std::string::size_type
pos = 0;
235 while (
pos != std::string::npos){
236 std::string::size_type
sep = xmlpath.find (
":",
pos);
237 if (
sep == std::string::npos){
238 temp_name = xmlpath.substr (
pos);
239 pos = std::string::npos;
241 temp_name = xmlpath.substr (
pos,
sep -
pos);
244 if (temp_name.empty())
continue;
245 std::string last_temp_name = temp_name;
249 std::cout <<
"ExpatCoreParser::generic_parse> file_name=" <<
file_name
250 <<
" xmlpath=" << xmlpath
251 <<
" temp_name=" << temp_name
255 docfd = fopen (temp_name.c_str (),
"r");
256 if (docfd != 0)
break;
259 temp_name = last_temp_name;
265 std::cout <<
"ExpatCoreParser::generic_parse> file_name=" <<
file_name
266 <<
" xmlpath=" << xmlpath
267 <<
" temp_name=" << temp_name
270 docfd = fopen (temp_name.c_str (),
"r");
271 if (docfd != 0)
break;
280 XML_SetParamEntityParsing (
p, XML_PARAM_ENTITY_PARSING_ALWAYS);
285 XML_SetUserData (
p,
this);
287 std::cout <<
"ExpatCoreParser::generic_parse> starting" << std::endl;
294 std::cout <<
"Read error" << std::endl;
298 int done = feof (docfd);
300 if (XML_ParseBuffer (
p,
BUFFSIZE, done) == XML_STATUS_ERROR) {
302 std::cout <<
"ExpatCoreParser::Parse error at line " << XML_GetCurrentLineNumber(
p)
305 << XML_ErrorString (XML_GetErrorCode(
p)) << std::endl;
319 std::cout <<
"ExpatCoreParser::generic_text_parse> " << std::endl;
322 XML_SetParamEntityParsing (
p, XML_PARAM_ENTITY_PARSING_ALWAYS);
327 XML_SetUserData (
p,
this);
329 std::cout <<
"ExpatCoreParser::generic_text_parse> starting" << std::endl;
332 char*
buff = (
char*) XML_GetBuffer (
p,
text.size() + 1);
335 if (XML_ParseBuffer (
p,
text.size(), done) == XML_STATUS_ERROR) {
336 std::cout <<
"ExpatCoreParser::Parse error at line " << XML_GetCurrentLineNumber(
p)
338 << XML_ErrorString (XML_GetErrorCode(
p)) << std::endl;
348 const XML_Char* context,
const XML_Char*
systemId){
349 std::string context_str;
350 if (context == 0) context_str =
"none";
351 else context_str = context;
356 if (replacement !=
"") {
358 std::cout <<
"ExpatCoreParser::do_external_entity> "
359 <<
" context=[" << context_str <<
"]"
360 <<
" replacement=[" << replacement <<
"]"
363 XML_Parser
p = XML_ExternalEntityParserCreate (
parser, context, NULL);
371 if (replacement ==
"NULL") {
374 if (replacement !=
"") {
379 std::cout <<
"ExpatCoreParser::do_external_entity> "
380 <<
" context=[" << context_str <<
"]"
382 <<
" replacement=[" << replacement <<
"]"
385 XML_Parser
p = XML_ExternalEntityParserCreate (
parser, context, NULL);
395 ExternalEntityMap::const_iterator
it = s_entities.find (
name);
396 if (
it == s_entities.end ()) {
397 static const std::string
empty;
400 return ((*it).second);
407 ExternalEntityMap::const_iterator
it = s_text_entities.find (
name);
408 if (
it == s_text_entities.end ()) {
409 static const std::string
empty;
412 return ((*it).second);
416 std::unique_ptr<CoreParser::DOMNode>
421 if (
pos != std::string::npos){
426 XML_Parser
p = XML_ParserCreate (NULL);
428 std::cout <<
"ExpatCoreParser::Couldn't allocate memory for parser" << std::endl;
433 if (
result == 0)
return nullptr;