Keep the original format when associating a DTD/schema/XSL
This commit is contained in:
parent
a8a6bf6a07
commit
b3ed8c5d69
|
@ -35,10 +35,10 @@ XmlAssociateDtd::XmlAssociateDtd (
|
|||
d->buffer.reserve ( size );
|
||||
d->path = path;
|
||||
d->publicID = publicID;
|
||||
d->rootElementSeen = false;
|
||||
d->associated = false;
|
||||
d->insideDtd = false;
|
||||
XML_SetUserData ( p, d.get() );
|
||||
XML_SetElementHandler ( p, start, end );
|
||||
XML_SetUserData ( p, this );
|
||||
XML_SetElementHandler ( p, start, NULL );
|
||||
XML_SetDoctypeDeclHandler ( p, startdoctypehandler, enddoctypehandler );
|
||||
XML_SetDefaultHandlerExpand ( p, defaulthandler );
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ void XMLCALL XmlAssociateDtd::defaulthandler (
|
|||
const XML_Char *s,
|
||||
int len )
|
||||
{
|
||||
DtdData *d;
|
||||
d = ( DtdData * ) data;
|
||||
XmlAssociateDtd *pThis = (XmlAssociateDtd *)data;
|
||||
DtdData *d = pThis->d.get();
|
||||
if ( !d->insideDtd )
|
||||
d->buffer.append ( s, len );
|
||||
}
|
||||
|
@ -61,51 +61,24 @@ void XMLCALL XmlAssociateDtd::start ( void *data,
|
|||
const XML_Char *el,
|
||||
const XML_Char **attr )
|
||||
{
|
||||
DtdData *d;
|
||||
d = ( DtdData * ) data;
|
||||
XmlAssociateDtd *pThis = (XmlAssociateDtd *)data;
|
||||
DtdData *d = pThis->d.get();
|
||||
|
||||
if ( !d->rootElementSeen )
|
||||
if ( !d->associated )
|
||||
{
|
||||
if ( d->publicID.empty() )
|
||||
{
|
||||
d->buffer += "<!DOCTYPE ";
|
||||
d->buffer += el;
|
||||
d->buffer += " SYSTEM \"";
|
||||
d->buffer += d->path.utf8_str(); // TODO: Apply the encoding of the parser
|
||||
d->buffer += "\">\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
d->buffer += "<!DOCTYPE ";
|
||||
d->buffer += el;
|
||||
d->buffer += " PUBLIC \"";
|
||||
d->buffer += d->publicID.utf8_str(); // TODO: Apply the encoding of the parser
|
||||
d->buffer += "\" \"";
|
||||
d->buffer += d->path.utf8_str();
|
||||
d->buffer += "\">\n";
|
||||
}
|
||||
d->rootElementSeen = true;
|
||||
associate ( d, el );
|
||||
d->buffer += "\n";
|
||||
d->associated = true;
|
||||
}
|
||||
|
||||
d->buffer += "<";
|
||||
d->buffer += el;
|
||||
|
||||
while ( *attr )
|
||||
{
|
||||
d->buffer += " ";
|
||||
d->buffer += *attr;
|
||||
d->buffer += "=\"";
|
||||
d->buffer += xmliseAttribute ( * ( attr + 1 ) );
|
||||
d->buffer += "\"";
|
||||
attr += 2;
|
||||
}
|
||||
d->buffer += ">";
|
||||
XML_DefaultCurrent ( pThis->p );
|
||||
XML_SetElementHandler ( pThis->p, NULL, NULL );
|
||||
}
|
||||
|
||||
void XMLCALL XmlAssociateDtd::end ( void *data, const XML_Char *el )
|
||||
{
|
||||
DtdData *d;
|
||||
d = ( DtdData * ) data;
|
||||
XmlAssociateDtd *pThis = (XmlAssociateDtd *)data;
|
||||
DtdData *d = pThis->d.get();
|
||||
d->buffer += "</";
|
||||
d->buffer += el;
|
||||
d->buffer += ">";
|
||||
|
@ -118,14 +91,38 @@ void XMLCALL XmlAssociateDtd::startdoctypehandler (
|
|||
const XML_Char *pubid,
|
||||
int has_internal_subset )
|
||||
{
|
||||
DtdData *d;
|
||||
d = ( DtdData * ) data;
|
||||
XmlAssociateDtd *pThis = (XmlAssociateDtd *)data;
|
||||
DtdData *d = pThis->d.get();
|
||||
d->insideDtd = true;
|
||||
|
||||
associate ( d, doctypeName );
|
||||
d->associated = true;
|
||||
}
|
||||
|
||||
void XMLCALL XmlAssociateDtd::enddoctypehandler ( void *data )
|
||||
{
|
||||
DtdData *d;
|
||||
d = ( DtdData * ) data;
|
||||
XmlAssociateDtd *pThis = (XmlAssociateDtd *)data;
|
||||
DtdData *d = pThis->d.get();
|
||||
d->insideDtd = false;
|
||||
}
|
||||
|
||||
void XmlAssociateDtd::associate ( DtdData *d, const char *doctypeName )
|
||||
{
|
||||
wxASSERT ( d );
|
||||
|
||||
d->buffer += "<!DOCTYPE ";
|
||||
d->buffer += doctypeName;
|
||||
if ( d->publicID.empty() )
|
||||
{
|
||||
d->buffer += " SYSTEM \"";
|
||||
d->buffer += d->path.utf8_str(); // TODO: Apply the encoding of the parser
|
||||
}
|
||||
else
|
||||
{
|
||||
d->buffer += " PUBLIC \"";
|
||||
d->buffer += d->publicID.utf8_str();
|
||||
d->buffer += "\" \"";
|
||||
d->buffer += d->path.utf8_str();// TODO: Apply the encoding of the parser
|
||||
}
|
||||
d->buffer += "\">";
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ struct DtdData : public ParserData
|
|||
{
|
||||
std::string buffer;
|
||||
wxString path, publicID;
|
||||
bool rootElementSeen, insideDtd;
|
||||
bool associated, insideDtd;
|
||||
};
|
||||
|
||||
class XmlAssociateDtd : public WrapExpat
|
||||
|
@ -67,6 +67,7 @@ class XmlAssociateDtd : public WrapExpat
|
|||
const XML_Char *pubid,
|
||||
int has_internal_subset );
|
||||
static void XMLCALL enddoctypehandler ( void *userData );
|
||||
static void associate ( DtdData *d, const char *doctypeName );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -36,10 +36,10 @@ XmlAssociateXsd::XmlAssociateXsd (
|
|||
{
|
||||
d->buffer.reserve ( size );
|
||||
d->path = path;
|
||||
d->rootElementSeen = false;
|
||||
d->depth = 0;
|
||||
XML_SetElementHandler ( p, start, end );
|
||||
XML_SetDefaultHandlerExpand ( p, defaulthandler );
|
||||
XML_SetUserData ( p, d.get() );
|
||||
XML_SetUserData ( p, this );
|
||||
|
||||
std::auto_ptr<XmlParseSchemaNs> parser ( new XmlParseSchemaNs() );
|
||||
std::string normalisedPath, buffer;
|
||||
|
@ -80,8 +80,8 @@ void XMLCALL XmlAssociateXsd::defaulthandler (
|
|||
{
|
||||
if ( !data || !s )
|
||||
return;
|
||||
AssociateXsdData *d;
|
||||
d = ( AssociateXsdData * ) data;
|
||||
XmlAssociateXsd *pThis = (XmlAssociateXsd *)data;
|
||||
AssociateXsdData *d = pThis->d.get();
|
||||
if ( d )
|
||||
d->buffer.append ( s, len );
|
||||
}
|
||||
|
@ -92,10 +92,17 @@ void XMLCALL XmlAssociateXsd::start ( void *data,
|
|||
{
|
||||
if ( !data )
|
||||
return;
|
||||
|
||||
AssociateXsdData *d;
|
||||
d = ( AssociateXsdData * ) data;
|
||||
|
||||
|
||||
XmlAssociateXsd *pThis = (XmlAssociateXsd *)data;
|
||||
AssociateXsdData *d = pThis->d.get();
|
||||
|
||||
d->depth++;
|
||||
if ( d->depth > 1 )
|
||||
{
|
||||
XML_DefaultCurrent ( pThis->p );
|
||||
return;
|
||||
}
|
||||
|
||||
d->buffer += "<";
|
||||
d->buffer += el;
|
||||
|
||||
|
@ -116,33 +123,31 @@ void XMLCALL XmlAssociateXsd::start ( void *data,
|
|||
}
|
||||
attr += 2;
|
||||
}
|
||||
if ( !d->rootElementSeen )
|
||||
{
|
||||
d->buffer += " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
for ( it = d->namespaceMap.begin(); it != d->namespaceMap.end(); ++it )
|
||||
{
|
||||
d->buffer += " ";
|
||||
d->buffer += it->first;
|
||||
d->buffer += "=\"";
|
||||
d->buffer += it->second;
|
||||
d->buffer += "\"";
|
||||
}
|
||||
|
||||
d->buffer += " xsi:";
|
||||
bool withNamespace =
|
||||
( d->namespaceMap.find ( "xmlns" ) != d->namespaceMap.end() );
|
||||
d->buffer += ( withNamespace ) ? "schemaLocation" : "noNamespaceSchemaLocation";
|
||||
d->buffer += " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
for ( it = d->namespaceMap.begin(); it != d->namespaceMap.end(); ++it )
|
||||
{
|
||||
d->buffer += " ";
|
||||
d->buffer += it->first;
|
||||
d->buffer += "=\"";
|
||||
if ( withNamespace )
|
||||
{
|
||||
d->buffer += d->namespaceMap["xmlns"];
|
||||
d->buffer += " ";
|
||||
}
|
||||
d->buffer += d->path.utf8_str(); // TODO: Apply the encoding of the parser
|
||||
d->buffer += it->second;
|
||||
d->buffer += "\"";
|
||||
d->rootElementSeen = true;
|
||||
}
|
||||
|
||||
d->buffer += " xsi:";
|
||||
bool withNamespace =
|
||||
( d->namespaceMap.find ( "xmlns" ) != d->namespaceMap.end() );
|
||||
d->buffer += ( withNamespace ) ? "schemaLocation" : "noNamespaceSchemaLocation";
|
||||
d->buffer += "=\"";
|
||||
if ( withNamespace )
|
||||
{
|
||||
d->buffer += d->namespaceMap["xmlns"];
|
||||
d->buffer += " ";
|
||||
}
|
||||
d->buffer += d->path.utf8_str(); // TODO: Apply the encoding of the parser
|
||||
d->buffer += "\"";
|
||||
|
||||
d->buffer += ">";
|
||||
}
|
||||
|
||||
|
@ -150,9 +155,15 @@ void XMLCALL XmlAssociateXsd::end ( void *data, const XML_Char *el )
|
|||
{
|
||||
if ( !data )
|
||||
return;
|
||||
AssociateXsdData *d;
|
||||
d = ( AssociateXsdData * ) data;
|
||||
d->buffer += "</";
|
||||
d->buffer += el;
|
||||
d->buffer += ">";
|
||||
XmlAssociateXsd *pThis = (XmlAssociateXsd *)data;
|
||||
AssociateXsdData *d = pThis->d.get();
|
||||
d->depth--;
|
||||
if ( d->depth )
|
||||
XML_DefaultCurrent ( pThis->p );
|
||||
else
|
||||
{
|
||||
d->buffer += "</";
|
||||
d->buffer += el;
|
||||
d->buffer += ">";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ struct AssociateXsdData : public ParserData
|
|||
{
|
||||
std::string buffer;//, namespaceAttribute;
|
||||
wxString path;
|
||||
bool rootElementSeen;
|
||||
size_t depth;
|
||||
std::map<std::string, std::string> namespaceMap;
|
||||
};
|
||||
|
||||
|
|
|
@ -33,9 +33,9 @@ XmlAssociateXsl::XmlAssociateXsl (
|
|||
{
|
||||
d->buffer.reserve ( size );
|
||||
d->path = path;
|
||||
d->rootElementSeen = false;
|
||||
XML_SetUserData ( p, d.get() );
|
||||
XML_SetElementHandler ( p, start, end );
|
||||
d->associated = false;
|
||||
XML_SetUserData ( p, this );
|
||||
XML_SetElementHandler ( p, start, NULL );
|
||||
XML_SetProcessingInstructionHandler ( p, processinghandler );
|
||||
XML_SetDefaultHandlerExpand ( p, defaulthandler );
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ void XMLCALL XmlAssociateXsl::defaulthandler (
|
|||
const XML_Char *s,
|
||||
int len )
|
||||
{
|
||||
XslData *d;
|
||||
d = ( XslData * ) data;
|
||||
XmlAssociateXsl *pThis = (XmlAssociateXsl *)data;
|
||||
XslData *d = pThis->d.get();
|
||||
d->buffer.append ( s, len );
|
||||
}
|
||||
|
||||
|
@ -57,36 +57,25 @@ void XMLCALL XmlAssociateXsl::start ( void *data,
|
|||
const XML_Char *el,
|
||||
const XML_Char **attr )
|
||||
{
|
||||
XslData *d;
|
||||
d = ( XslData * ) data;
|
||||
XmlAssociateXsl *pThis = (XmlAssociateXsl *)data;
|
||||
XslData *d = pThis->d.get();
|
||||
|
||||
if ( !d->rootElementSeen )
|
||||
if ( !d->associated )
|
||||
{
|
||||
d->buffer += "<?xml-stylesheet type=\"text/xsl\" href=\"";
|
||||
d->buffer += d->path.utf8_str(); // TODO: Apply the encoding of the parser
|
||||
d->buffer += "\"?>\n";
|
||||
d->rootElementSeen = true;
|
||||
d->associated = true;
|
||||
}
|
||||
|
||||
d->buffer += "<";
|
||||
d->buffer += el;
|
||||
|
||||
while ( *attr )
|
||||
{
|
||||
d->buffer += " ";
|
||||
d->buffer += *attr;
|
||||
d->buffer += "=\"";
|
||||
d->buffer += xmliseAttribute ( * ( attr + 1 ) );
|
||||
d->buffer += "\"";
|
||||
attr += 2;
|
||||
}
|
||||
d->buffer += ">";
|
||||
XML_DefaultCurrent ( pThis->p );
|
||||
XML_SetElementHandler ( pThis->p, NULL, NULL );
|
||||
}
|
||||
|
||||
void XMLCALL XmlAssociateXsl::end ( void *data, const XML_Char *el )
|
||||
{
|
||||
XslData *d;
|
||||
d = ( XslData * ) data;
|
||||
XmlAssociateXsl *pThis = (XmlAssociateXsl *)data;
|
||||
XslData *d = pThis->d.get();
|
||||
d->buffer += "</";
|
||||
d->buffer += el;
|
||||
d->buffer += ">";
|
||||
|
@ -97,15 +86,24 @@ void XMLCALL XmlAssociateXsl::processinghandler (
|
|||
const XML_Char *target,
|
||||
const XML_Char *datastring )
|
||||
{
|
||||
XslData *d;
|
||||
d = ( XslData * ) data;
|
||||
XmlAssociateXsl *pThis = (XmlAssociateXsl *)data;
|
||||
XslData *d = pThis->d.get();
|
||||
|
||||
if ( !strcmp ( target, "xml-stylesheet" ) )
|
||||
return;
|
||||
{
|
||||
d->buffer += "<?xml-stylesheet type=\"text/xsl\" href=\"";
|
||||
d->buffer += d->path.utf8_str(); // TODO: Apply the encoding of the parser
|
||||
d->buffer += "\"?>";
|
||||
d->associated = true;
|
||||
|
||||
d->buffer += "<?";
|
||||
d->buffer += target;
|
||||
d->buffer += " ";
|
||||
d->buffer += datastring;
|
||||
d->buffer += "?>";
|
||||
XML_SetElementHandler ( pThis->p, NULL, NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
d->buffer += "<?";
|
||||
d->buffer += target;
|
||||
d->buffer += " ";
|
||||
d->buffer += datastring;
|
||||
d->buffer += "?>";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ struct XslData : public ParserData
|
|||
{
|
||||
std::string buffer;
|
||||
wxString path;
|
||||
bool rootElementSeen;
|
||||
bool associated;
|
||||
};
|
||||
|
||||
class XmlAssociateXsl : public WrapExpat
|
||||
|
|
Loading…
Reference in New Issue