1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include "GUI.h"
GUI::GUI(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) :
MyFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE)
{
Connect(button_1->GetId(),wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(GUI::OnLoadXML));
}
void GUI::LoadXML(const wxString &filename)
{
wxXml2Document doc;
wxString err;
wxFileInputStream tmp(filename);
if (tmp.IsOk() && tmp.GetSize() > 2048)
// parse the file
if (!doc.Load(filename, &err)) {
wxMessageBox(wxString::Format(
wxT("Couldn't parse the file you chose:\n%s"), err.c_str()), wxT("Error"));
return;
}
// show the wxXml2Node tree in a simple format...
wxString tree;
wxXml2Node root = doc.GetRoot();
int indent = 3;
tree.Alloc(1024);
// show the DTD declaration, if present
wxXml2DTD dtd(doc.GetDTD());
if (dtd != wxXml2EmptyDTD) {
tree += wxT("DTD name=") + dtd.GetName();
if (dtd.IsPublicSubset())
tree += wxT(" PUBLIC externalID=") + dtd.GetExternalID() +
wxT(" externalURI=") + dtd.GetExternalURI() + wxT("\n\n");
if (dtd.IsSystemSubset())
tree += wxT(" SYSTEM systemID=") + dtd.GetSystemID() + wxT("\n\n");
}
// get a string with the tree structure...
// ParseNodeAndSiblings(root, tree, indent);
// show it to the user
text_ctrl_2->SetValue(tree);
// cleanup
dtd.DestroyIfUnlinked();
root.DestroyIfUnlinked();
doc.DestroyIfUnlinked();
}
void GUI::OnLoadXML(wxCommandEvent& WXUNUSED(event))
{
wxFileDialog fd(this, wxT("Choose the XML file to load"), wxT(""), wxT(""),
wxT("XML and HTML files|*.xml;*.html;*.xhtml|All files|*.*"), wxOPEN);
if (fd.ShowModal() == wxID_CANCEL)
return;
LoadXML(fd.GetPath());
wxXml2Document tmpDoc;
tmpDoc.Load(fd.GetPath());
] |
Partager