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: November 6, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • A modern mobile IT strategy is no longer an option, it is an absolute business necessity. Today's most productive employees are not tied to a desk, an office, or a location. They are mobile. And your company's IT strategy has to be ready to support them with easy, reliable, 24/7 access to the business information they need, from anywhere in the world, across a broad range of communication devices. Here's how some of the nation's most progressive corporations are meeting the many needs of their mobile workers …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds