diff --git a/src/wraplibxml.cpp b/src/wraplibxml.cpp index 2f231e3..61b7f34 100644 --- a/src/wraplibxml.cpp +++ b/src/wraplibxml.cpp @@ -145,7 +145,7 @@ bool WrapLibxml::validate ( const std::string& utf8DocBuf, } bool WrapLibxml::validateRelaxNG ( - const wxString &schemaFileName, + const wxString &schemaUrl, const std::string &utf8DocBuf, const wxString &docFileName ) { @@ -159,9 +159,7 @@ bool WrapLibxml::validateRelaxNG ( xmlRelaxNGPtr schemaPtr = NULL; do { - xmlChar *url = xmlFileNameToURL ( schemaFileName ); - rngParserCtxt = xmlRelaxNGNewParserCtxt ( ( const char * ) url ); - xmlFree ( url ); + rngParserCtxt = xmlRelaxNGNewParserCtxt ( schemaUrl.utf8_str() ); if ( rngParserCtxt == NULL ) { nonParserError = _("Cannot create an RNG parser context"); @@ -187,7 +185,7 @@ bool WrapLibxml::validateRelaxNG ( int flags = XML_PARSE_DTDVALID; if ( !netAccess ) flags |= XML_PARSE_NONET; - url = xmlFileNameToURL ( docFileName ); + xmlChar *url = xmlFileNameToURL ( docFileName ); docPtr = xmlCtxtReadMemory ( ctxt, utf8DocBuf.c_str(), utf8DocBuf.length(), ( const char * ) url, "UTF-8", flags ); xmlFree ( url ); diff --git a/src/wraplibxml.h b/src/wraplibxml.h index 7dc93b9..37c7286 100644 --- a/src/wraplibxml.h +++ b/src/wraplibxml.h @@ -50,7 +50,7 @@ class WrapLibxml const std::string &utf8DocBuf, const wxString &docFileName ); bool validateRelaxNG ( - const wxString &schemaFileName, + const wxString &schemaUrl, const std::string &utf8DocBuf, const wxString &docFileName ); bool validateW3CSchema ( diff --git a/src/xmlcopyeditor.cpp b/src/xmlcopyeditor.cpp index 34ecf48..a24255f 100644 --- a/src/xmlcopyeditor.cpp +++ b/src/xmlcopyeditor.cpp @@ -3825,20 +3825,19 @@ void MyFrame::OnValidateRelaxNG ( wxCommandEvent& event ) if ( ad.ShowModal() != wxID_OK ) return; - wxString path = lastRelaxNGSchema = ad.getUrl(); - - if ( path.empty() ) + const wxString &url = lastRelaxNGSchema = ad.getUrl(); + if ( url.empty() ) { statusProgress ( wxEmptyString ); return; } - validateRelaxNG ( doc, path, fileName ); + validateRelaxNG ( doc, url, fileName ); } void MyFrame::validateRelaxNG ( XmlDoc *doc, - const wxString& schemaName, + const wxString& schemaUrl, wxString& fileName ) // not const: may change if empty/document modified { statusProgress ( wxEmptyString ); @@ -3846,13 +3845,11 @@ void MyFrame::validateRelaxNG ( if ( !doc ) return; - doc->clearErrorIndicators(); statusProgress ( _ ( "RELAX NG validation in progress..." ) ); auto_ptr wl ( new WrapLibxml ( libxmlNetAccess ) ); - - if ( !wl->validateRelaxNG ( schemaName, doc->myGetTextRaw(), fileName ) ) + if ( !wl->validateRelaxNG ( schemaUrl, doc->myGetTextRaw(), fileName ) ) { wxString wideError = wl->getLastError(); statusProgress ( wxEmptyString ); @@ -3883,10 +3880,10 @@ void MyFrame::OnValidatePreset ( wxCommandEvent& event ) wxString fileName = doc->getFullFileName(); int id = event.GetId(); - wxString schemaFileName = validationPresetMap[id]; - if ( schemaFileName.empty() ) + const wxString &schemaUrl = validationPresetMap[id]; + if ( schemaUrl.empty() ) return; - validateRelaxNG ( doc, schemaFileName, fileName ); + validateRelaxNG ( doc, schemaUrl, fileName ); } void MyFrame::OnValidateSchema ( wxCommandEvent& event ) @@ -5115,32 +5112,24 @@ wxMenuBar *MyFrame::getMenuBar() if ( wxDirExists ( rngDir ) ) { - wxString rngMask, rngFile, displayName, shortcutString; + wxString rngMask, rngFile, rngUrl, displayName, shortcutString; rngMask = rngDir + wxFileName::GetPathSeparator() + _T ( "*.rng" ); rngFile = wxFindFirstFile ( rngMask, wxFILE ); int id = ID_VALIDATE_PRESET1; - if ( !rngFile.empty() ) + while ( id <= ID_VALIDATE_PRESET9 && !rngFile.empty() ) { - validationPresetMap.insert ( make_pair ( id, rngFile ) ); + rngUrl = WrapLibxml::FileNameToURL ( rngFile ); + validationPresetMap.insert ( make_pair ( id, rngUrl ) ); wxFileName::SplitPath ( rngFile, NULL, NULL, &displayName, NULL ); displayName.Replace ( _T ( ".rng" ), _T ( "" ) ); shortcutString.Printf ( _ ( "\tCtrl+%i" ), ( id - ID_VALIDATE_PRESET1 ) + 1 ); validationMenu->Append ( id, displayName + shortcutString, displayName ); - for ( id = ID_VALIDATE_PRESET2; id <= ID_VALIDATE_PRESET9; ++id ) - { - rngFile = wxFindNextFile(); - if ( rngFile.empty() ) - break; - validationPresetMap.insert ( make_pair ( id, rngFile ) ); - wxFileName::SplitPath ( rngFile, NULL, NULL, &displayName, NULL ); - shortcutString.Printf ( _ ( "\tCtrl+%i" ), ( id - ID_VALIDATE_PRESET1 ) + 1 ); - displayName.Replace ( _T ( ".rng" ), _T ( "" ) ); - validationMenu->Append ( id, displayName + shortcutString, displayName ); - } + id++; + rngFile = wxFindNextFile(); } }