CXmlMenu'�Display Menus from XML Files

Environment: VC6

This article covers the need for the dynamic creation of menus from XML files. Menus represent tree data structures exactly as XML files do. In case you have some data stored in an XML file and you want to select a specific item from it, wouldn't it be nice to have something like this:

CXmlMenu menu;

//display the menu and get user selection
CString answer = menu.TrackXml(this,"example.xml","name");

if (answer!="")
  MessageBox("You selected \"" + answer + "\"");

This is exactly what the CXmlMenu class does. It can create a menu by reading a specific attribute of the items of an XML file (attribute "name" is selected in the example above); it displays the menu and returns the attribute of the selected item.

The code for XML file handling is taken from Pablo van der Meer.

Downloads

Download demo project - 129 Kb
Download source - 6 Kb


Comments

  • Plz help me

    Posted by rindam2002 on 06/04/2007 05:54am

    I am being unamble to create menu from an xml file which I am loading through its url.why?plz help me out.its really urgent.

    Reply
  • Plz help me

    Posted by rindam2002 on 06/04/2007 05:52am

    I am being unamble to create menu from an xml file which I am loading through its url.why?plz help me out.its really urgent.

    Reply
  • Help Required Urgently

    Posted by shash123 on 11/16/2006 05:24am

    Please help me out.I posted the question yesterday also. I want to read an XML file from a web location by specifying its URL, but I am not able to do so through this program. Please reply me as soon as possible. Thanks in Advance

    • reading xml file from a web location is solved

      Posted by rindam2002 on 06/05/2007 01:17am

      Hi shashank I was also having the same problem but I have solved it now...Just copy the bellow code in place of load function and enjoy. MSXML::IXMLDOMDocumentPtr pDOMDoc(__uuidof (MSXML::DOMDocument)); m_plDomDocument = pDOMDoc; pDOMDoc->put_async(VARIANT_FALSE); VARIANT_BOOL vResult1 = pDOMDoc->load(_variant_t(bstrFileName1)); if (VARIANT_FALSE == vResult1) { // Load failed MSXML::IXMLDOMParseErrorPtr pParseError = pDOMDoc->GetparseError(); long dwError = pParseError->GeterrorCode(); _bstr_t bstrReason = pParseError->Getreason(); CString strError; strError.Format(_T("XML Parse Error 0x%x : %s"), dwError, W2T(bstrReason)); MessageBox(strError); }

      Reply
    Reply
  • Reading XML file from a web location.....

    Posted by shash123 on 11/14/2006 11:50pm

    Hi,
    This was really a nice program.
    But I am unable to read any XML file if a provided its URL instead of the local disk path.
    Can u please tell me hoe to do it?
    
    Regards
    
    Shashank

    • reading xml file from a web location

      Posted by rindam2002 on 06/04/2007 05:48am

      hi I am also facing the same problem.I am unable to read any XML file if a provided its URL instead of the local disk path.Plz tell me how to do it?

      Reply
    Reply
  • good

    Posted by dwoseven on 06/19/2004 02:46pm

    good program

    Reply
  • Little bug

    Posted by Legacy on 11/25/2003 12:00am

    Originally posted by: emilio_g

    An annoying bug when reading the file: nothing serius
    
    but ...

    You use CString::GetBuffer, to obtain a buffer to fill,
    than you read as meny characters from the file as the file len.
    This does not null-terminate the string.

    To correct:
    1) Call GetBuffer and store the result in a LPTSTR local variable (the lenght should be the file lenght + 1)
    2) Read the file into the buffer
    3) set the last character to \0 (buffer[len] = 0;
    4) call ReleaseBuffer()

    ReleseBuffer will recalculete the length, but now will not
    go ahed the length of the string, avoiding the assertion.


    • some code...

      Posted by Michael Klim on 08/15/2004 11:28am

      Hi Could you please post the code here or update the application, because I have really big problems implementing the hints of emilio... Thanks in advance, Michael

      Reply
    • thanks!

      Posted by jmelas on 08/05/2004 05:00am

      The code for XmlDocument is not mine but I found also this bug when I installed VC7.0! Thanks for the correction!

      Reply
    Reply
  • Great program!!

    Posted by Legacy on 11/20/2003 12:00am

    Originally posted by: Raul Assis

    Great program!! It worked very well. Now it would be great to expand the program not only to display the contents of xml files but to enable editing.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds