From: cecilio <s.c...@gm...> - 2006-11-29 11:08:14
|
Hi Francesco, I'm trying to use wxXml2 and I've found two problems. I am using Windows XP, MSVC and wxWidgets 2.8.0rc1. The problems are: 1. In Unicode build (Debug Unicode) messages from libxml2 are not properly displayed. See attached filed: - 'ok.jpg' for the right output (minimal sample build in 'Debug' configuration) - 'wrong.jpg' for the same xml file processed with minimal sample build in 'Debug Unicode' configuration. 2. External entities are not properly included in the processed file. Just the name of the entity is included. As an example find attached three files: - 'document.xml' the XML document to process (menu LoadXML in minimal sample). This xml file is copied from book 'The XML bible, listing 9-4 - 'signature.xml' this file is the content of the external entity. Copied from the same book, listing 9-3 - 'output.jpg' is the output window of minimal sample. You can see that external entity &SIG; has been replaced just by its name instead of include its content. Am I doing something wrong? Regards, Cecilio |
From: Francesco M. <f18...@ya...> - 2006-11-29 18:47:16
|
cecilio ha scritto: > Hi Francesco, > > I'm trying to use wxXml2 and I've found two problems. I am using > Windows XP, MSVC and wxWidgets 2.8.0rc1. The problems are: > > 1. In Unicode build (Debug Unicode) messages from libxml2 are not > properly displayed. See attached filed: > - 'ok.jpg' for the right output (minimal sample build in 'Debug' > configuration) > - 'wrong.jpg' for the same xml file processed with minimal sample > build in 'Debug Unicode' configuration. Very strange - I'm rebuilding wx now in Unicode mode so that I can test it. > 2. External entities are not properly included in the processed file. > Just the name of the entity is included. As an example find attached > three files: > - 'document.xml' the XML document to process (menu LoadXML in minimal > sample). This xml file is copied from book 'The XML bible, listing 9-4 > - 'signature.xml' this file is the content of the external entity. > Copied from the same book, listing 9-3 > - 'output.jpg' is the output window of minimal sample. You can see > that external entity &SIG; has been replaced just by its name instead > of include its content. sincerely I don't remember if I ever added support for external entities in wxXml2... I'll have a look at it when I have time (which means not so soon unfortunately): if you need this feature in brief time you may want to look at libxml2 documentation and see how you can enable that in libxml2 and then wrap required function calls in wxXml2... Francesco |
From: cecilio <s.c...@gm...> - 2006-11-29 21:25:42
|
HI Francesco, > Very strange - I'm rebuilding wx now in Unicode mode so that I can test it. OK. Thank you. > sincerely I don't remember if I ever added support for external entities > in wxXml2... I'll have a look at it when I have time (which means not so > soon unfortunately): if you need this feature in brief time you may want > to look at libxml2 documentation and see how you can enable that in > libxml2 and then wrap required function calls in wxXml2... Any clue about where should I start looking in wxXml2? Thank you. Regards, Cecilio |
From: Francesco M. <f18...@ya...> - 2006-12-05 13:07:15
|
cecilio ha scritto: > HI Francesco, > >> Very strange - I'm rebuilding wx now in Unicode mode so that I can test it. > OK. Thank you. sorry - I have been very busy and didn't manage to take a look at this yet... > >> sincerely I don't remember if I ever added support for external entities >> in wxXml2... I'll have a look at it when I have time (which means not so >> soon unfortunately): if you need this feature in brief time you may want >> to look at libxml2 documentation and see how you can enable that in >> libxml2 and then wrap required function calls in wxXml2... > > Any clue about where should I start looking in wxXml2? the problem is probably to understand how to do it in libxml2 (which api call in which order, etc) - then the wrapping should be easy (maybe just a matter of adding some functions to wxXml2Document)... Thanks, Francesco |
From: cecilio <s.c...@gm...> - 2006-12-05 16:57:40
|
Thanks, Francesco, > > Any clue about where should I start looking in wxXml2? > the problem is probably to understand how to do it in libxml2 (which api > call in which order, etc) - then the wrapping should be easy (maybe just > a matter of adding some functions to wxXml2Document)... Sorry, I wrote wxXml2 but I a was thinking on libxml2. As you know libxml is a huge package and the documentation is not for starters. So it is very difficult for me to know how to start. Any idea? |
From: Francesco M. <f18...@ya...> - 2006-12-05 19:16:34
|
cecilio ha scritto: > Thanks, Francesco, > >>> Any clue about where should I start looking in wxXml2? >> the problem is probably to understand how to do it in libxml2 (which api >> call in which order, etc) - then the wrapping should be easy (maybe just >> a matter of adding some functions to wxXml2Document)... > > Sorry, I wrote wxXml2 but I a was thinking on libxml2. As you know > libxml is a huge package and the documentation is not for starters. So > it is very difficult for me to know how to start. Any idea? ok, looked a bit deeper in this subject. Thanks to the comments I did put in wxXml2 sources (go me! ;)) you may be lucky: everything you need to do it "manually" is probably in wxXml2 already. Most probably there's a smarter way in libxml2 (see e.g. xmlLoadExternalEntity at http://xmlsoft.org/html/libxml-parser.html). If you want to do it "by hand" I think the following _may_ work: 1) after loading your doc, you need wxXml2Document::GetDTD 2) inside your wxXml2DTD you'll find the wxXml2EntityDecl nodes 3) for each of those node you need to use the GetContent() function and if a valid filename is returned load it using wxXml2Document 4) parse your original tree and replace the wxXML2_ENTITY_REF_NODE with the root of the wxXml2Document loaded at step #3 ok, after all it may reveal that libxml2 API is much more optimized and faster to use ;) Francesco |
From: cecilio <s.c...@gm...> - 2006-12-05 21:13:36
|
Many thanks. I will try and tell you about. Thanks again. Cecilio 2006/12/5, Francesco Montorsi <f18...@ya...>: > cecilio ha scritto: > > Thanks, Francesco, > > > >>> Any clue about where should I start looking in wxXml2? > >> the problem is probably to understand how to do it in libxml2 (which api > >> call in which order, etc) - then the wrapping should be easy (maybe just > >> a matter of adding some functions to wxXml2Document)... > > > > Sorry, I wrote wxXml2 but I a was thinking on libxml2. As you know > > libxml is a huge package and the documentation is not for starters. So > > it is very difficult for me to know how to start. Any idea? > ok, looked a bit deeper in this subject. Thanks to the comments I did put in > wxXml2 sources (go me! ;)) you may be lucky: everything you need to do it > "manually" is probably in wxXml2 already. > Most probably there's a smarter way in libxml2 (see e.g. xmlLoadExternalEntity > at http://xmlsoft.org/html/libxml-parser.html). > > If you want to do it "by hand" I think the following _may_ work: > 1) after loading your doc, you need wxXml2Document::GetDTD > 2) inside your wxXml2DTD you'll find the wxXml2EntityDecl nodes > 3) for each of those node you need to use the GetContent() function and if a > valid filename is returned load it using wxXml2Document > 4) parse your original tree and replace the wxXML2_ENTITY_REF_NODE with the root > of the wxXml2Document loaded at step #3 > > ok, after all it may reveal that libxml2 API is much more optimized and faster > to use ;) > > Francesco > > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > wxCode-users mailing list > wxC...@li... > https://lists.sourceforge.net/lists/listinfo/wxcode-users > |
From: cecilio <s.c...@gm...> - 2006-12-08 17:59:42
|
Hi Francesco, I briefly inform you about situation: >> 1) after loading your doc, you need wxXml2Document::GetDTD >> 2) inside your wxXml2DTD you'll find the wxXml2EntityDecl nodes >> 3) for each of those node you need to use the GetContent() function and if a >> valid filename is returned load it using wxXml2Document >> 4) parse your original tree and replace the wxXML2_ENTITY_REF_NODE with the root >> of the wxXml2Document loaded at step #3 After some trial and error trying to implement your "manual" proposed solution, I have found that steps 1,2 and 3 are not necessary. I modified the sample code to dump all the nodes. Then I discovered that when you include an external entity ( &name; ) the XML doc tree contains in its place an wxXML_ENTITY_REF_NODE, having an wxXML_ENTITY_DECL child. And this last one contains all needed information (GetSystemID contains the URL to load). So I think that only step 4, done on the fly, as you process the main document, is necessary. This is the code I added to your sample, in ParseNode(), before the else: else if (node.GetType() == wxXML_ENTITY_REF_NODE) { toadd += wxString::Format(_T(", NodeType=%d, Name='%s'"), node.GetType(), node.GetName()); } 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() ); } To be continued ... Regards, Cecilio |
From: cecilio <s.c...@gm...> - 2006-12-09 11:23:38
|
Hi Francesco, This is just to confirm you that replacing external entities on the fly works. 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; } 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. - I did not tested this code in the sample, but in my app, so maybe there is some bug in last line (toadd += sChildTree). Thank you again for your help, Regards, Cecilio. |
From: Francesco M. <f18...@ya...> - 2006-12-13 11:14:01
|
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 |
From: cecilio <s.c...@gm...> - 2006-12-29 15:36:51
Attachments:
minimal.cpp
|
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 > |
From: Francesco M. <f18...@ya...> - 2007-01-03 10:30:16
|
Hi, cecilio ha scritto: > 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. well actually I did forget that I moved wxXml2 to SVN so that it's in wxCode SVN and not in wxCode CVS... ;) > Therefore I am sending you the full modified source file. this is ok anyway. > 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. Sure, thanks! I'll check it in asap. Francesco |