74 const XML_Char* context,
79 void* user_data = XML_GetUserData (
parser);
88 std::cout <<
"ExpatCoreParser::register_external_entity> name=" <<
name
89 <<
" file_name=" <<
file_name << std::endl;
100 std::cout <<
"ExpatCoreParser::register_text_entity> name=" <<
name
109 const XML_Char* entityName,
110 int is_parameter_entity,
111 const XML_Char*
value,
113 const XML_Char*
base,
115 const XML_Char* publicId,
120 if (!publicId) publicId =
"none";
122 std::string temp =
"none";
126 char*
t = (
char*)
malloc (value_length + 1);
127 strncpy (
t,
value, value_length);
130 temp = (
const char*)
t;
141 std::cout <<
"ExpatCoreParser::entity[" << 0 <<
"]> " << entityName;
142 std::cout <<
" is_parameter=" << is_parameter_entity;
143 std::cout <<
" value=[" << temp <<
"]";
144 std::cout <<
" base=[" <<
base <<
"]";
145 std::cout <<
" systemId=[" <<
systemId <<
"]";
146 std::cout <<
" publicId=[" << publicId <<
"]";
147 std::cout << std::endl;
153 return std::move(
m_top);
167 std::map <std::string, std::string>
a;
171 m_top = std::make_unique<CoreParser::DOMNode> ();
179 std::cout <<
"ExpatCoreParser::do_start> el=" <<
el <<
" top=" <<
m_top.get() <<
" last=" <<
m_last <<
" node=" <<
node << std::endl;
184 for (
i = 0; attr[
i];
i += 2)
186 const char*
name = attr[
i];
187 const char*
value = attr[
i+1];
197 std::cout <<
"ExpatCoreParser::do_end> el=" <<
el << std::endl;
205 if (len == 0)
return;
207 while ((len > 0) && (
s[len-1] ==
'\n')) len--;
209 if (len == 0)
return;
211 char* temp = (
char*)
malloc (len + 1);
212 strncpy (temp,
s, len);
217 std::cout <<
"ExpatCoreParser::do_char_data> [" << temp <<
"]" << std::endl;
225 if (len == 0)
return;
227 while ((len > 0) && (
s[len-1] ==
'\n')) len--;
229 if (len == 0)
return;
231 char* temp = (
char*)
malloc (len + 1);
232 strncpy (temp,
s, len);
237 std::cout <<
"ExpatCoreParser::do_default_handler> [" << temp <<
"]" << std::endl;
247 m_top = std::make_unique<CoreParser::DOMNode> ();
255 std::cout <<
"ExpatCoreParser::do_comment> s=" <<
s <<
" top=" <<
m_top.get() <<
" last=" <<
m_last <<
" node=" <<
node << std::endl;
269 std::cout <<
"ExpatCoreParser::generic_parse> file_name=" <<
file_name <<
" prefix=" <<
m_prefix << std::endl;
274 docfd = fopen (temp_name.c_str (),
"r");
279 docfd = fopen (temp_name.c_str (),
"r");
284 const char* xmlpathenv =
::getenv (
"XMLPATH");
286 if (xmlpathenv == 0)
return (0);
288 std::string xmlpath = xmlpathenv;
290 std::string::size_type
pos = 0;
292 while (
pos != std::string::npos)
294 std::string::size_type
sep = xmlpath.find (
":",
pos);
296 if (
sep == std::string::npos)
298 temp_name = xmlpath.substr (
pos);
299 pos = std::string::npos;
303 temp_name = xmlpath.substr (
pos,
sep -
pos);
307 if (temp_name ==
"")
continue;
309 std::string last_temp_name = temp_name;
316 std::cout <<
"ExpatCoreParser::generic_parse> file_name=" <<
file_name
317 <<
" xmlpath=" << xmlpath
318 <<
" temp_name=" << temp_name
322 docfd = fopen (temp_name.c_str (),
"r");
323 if (docfd != 0)
break;
328 temp_name = last_temp_name;
336 std::cout <<
"ExpatCoreParser::generic_parse> file_name=" <<
file_name
337 <<
" xmlpath=" << xmlpath
338 <<
" temp_name=" << temp_name
342 docfd = fopen (temp_name.c_str (),
"r");
343 if (docfd != 0)
break;
355 XML_SetParamEntityParsing (
p, XML_PARAM_ENTITY_PARSING_ALWAYS);
360 XML_SetUserData (
p,
this);
367 std::cout <<
"ExpatCoreParser::generic_parse> starting" << std::endl;
380 std::cout <<
"Read error" << std::endl;
385 int done = feof (docfd);
391 if (XML_ParseBuffer (
p,
BUFFSIZE, done) == XML_STATUS_ERROR)
395 std::cout <<
"ExpatCoreParser::Parse error at line " << XML_GetCurrentLineNumber(
p)
398 << XML_ErrorString (XML_GetErrorCode(
p)) << std::endl;
415 std::cout <<
"ExpatCoreParser::generic_text_parse> " << std::endl;
420 XML_SetParamEntityParsing (
p, XML_PARAM_ENTITY_PARSING_ALWAYS);
425 XML_SetUserData (
p,
this);
432 std::cout <<
"ExpatCoreParser::generic_text_parse> starting" << std::endl;
437 char*
buff = (
char*) XML_GetBuffer (
p,
text.size() + 1);
442 if (XML_ParseBuffer (
p,
text.size(), done) == XML_STATUS_ERROR)
444 std::cout <<
"ExpatCoreParser::Parse error at line " << XML_GetCurrentLineNumber(
p)
446 << XML_ErrorString (XML_GetErrorCode(
p)) << std::endl;
457 const XML_Char* context,
460 std::string context_str;
462 if (context == 0) context_str =
"none";
463 else context_str = context;
472 if (replacement !=
"")
476 std::cout <<
"ExpatCoreParser::do_external_entity> "
477 <<
" context=[" << context_str <<
"]"
478 <<
" replacement=[" << replacement <<
"]"
482 XML_Parser
p = XML_ExternalEntityParserCreate (
parser, context, NULL);
496 if (replacement ==
"NULL")
501 if (replacement !=
"")
508 std::cout <<
"ExpatCoreParser::do_external_entity> "
509 <<
" context=[" << context_str <<
"]"
511 <<
" replacement=[" << replacement <<
"]"
515 XML_Parser
p = XML_ExternalEntityParserCreate (
parser, context, NULL);
529 ExternalEntityMap::const_iterator
it = s_entities.find (
name);
530 if (
it == s_entities.end ())
532 static const std::string
empty;
537 return ((*it).second);
544 ExternalEntityMap::const_iterator
it = s_text_entities.find (
name);
545 if (
it == s_text_entities.end ())
547 static const std::string
empty;
552 return ((*it).second);
556 std::unique_ptr<CoreParser::DOMNode>
563 if (
pos != std::string::npos)
570 XML_Parser
p = XML_ParserCreate (NULL);
574 std::cout <<
"ExpatCoreParser::Couldn't allocate memory for parser" << std::endl;