From: cecilio <s.c...@gm...> - 2006-12-29 15:36:51
|
Hi Francesco, Sorry for the delay. >> could you submit it as a patch? >> It's much easier to apply in that form (just do a "cvs diff -bu2 >sample.patch" in wxXml2\sample). Well I am very new to CVS and SVN so I dont know how to prepare the patch. But in any case, I moved to SVN and currently I don't have CVS installed, so I can not execute the suggested command. Therefore I am sending you the full modified source file. I built the sample and tested it. It works ok: external entities are detected and replaced correctly. There was a bug in the code I sketched in my previous e-mail, as it only worked ok if the xml file being processed has only one external entity defined. If it has more than one definition, I have discovered that after a node of type wxXML_ENTITY_REF_NODE you will find, as children, the full list of declared external entities. So I had to modify the code to choose the proper one. The attached code is tested and works ok. Hope this is OK for you. Regards, Cecilio 2006/12/13, Francesco Montorsi <f18...@ya...>: > Hi Cecilio, > sorry again for the delay... > > cecilio ha scritto: > > This is just to confirm you that replacing external entities on the > > fly works. > very good! > > > The following code is the modification to add to your > > sample code: > > > > else if (node.GetType() == wxXML_ENTITY_DECL) > > { > > wxXml2EntityDecl* pNode = (wxXml2EntityDecl*)&node; > > toadd += wxString::Format(_T(", NodeType=%d, Name='%s', > > SystemID='%s'\n"), > > node.GetType(), pNode->GetSystemID() ); > > > > // insert here the referenced xml tree > > > > // load the referebced XML file as tree of nodes > > wxXml2Document oDoc; > > wxString sError; > > wxFileName oFN(m_sMainFilename); > > oFN.SetFullName(pNode->GetSystemID()); > > wxString sFilename = oFN.GetFullPath(); > > if (!oDoc.Load(sFilename, &sError)) { > > wxLogMessage(_T("Error parsing file %s\nError:%s"), > > sFilename, sError); > > return; // or continue? > > } > > //Process it recursively > > wxXml2Node oRoot = oDoc.GetRoot(); > > wxString sChildTree; > > ParseNodeAndSiblings(oRoot, sChildTree, n); > > toadd += sChildTree; > > } > great - nice addition to the sample; could you submit it as a patch? > It's much easier to apply in that form (just do a "cvs diff -bu2 > >sample.patch" in wxXml2\sample). > > > > > > Two important issues: > > > > 1. You will see global variable m_sMainFilename. This is needed > > because the external entity URL could be relative to main file. So we > > need to know the main file URL. A second issue is that in this sample > > code I am assuming that the external entity URL is just > > "filename.ext", so that it will be located at the same folder than > > main XML file. > > This is a non-valid assuption and so, more code must be > > inserted to compose the rigth URL. > aren't these two issues the same ? > I'd simply write: > > wxFileName oFN(pNode->GetSystemID()); > if (oFN.IsRelative()) > oFN.MakeAbsolute(wxPathOnly(m_sMainFilename)); > > > - I did not tested this code in the sample, but in my app, so maybe > > there is some bug in last line (toadd += sChildTree). > I'll look at it.... > > Thanks, > Francesco > |