Click here to Skip to main content
Click here to Skip to main content

XML TreeCtrl

By , 6 Aug 2002
 

Introduction

Recently, I needed to display XML files or XML representation of COM objects in a tree control. After some web surfing, I didn't find any ActiveX Control ready to use. So, I decided to develop this one. The ActiveX is based on the XML Apache SAX Parser, Xerces v1.4 (xml.apache.org). It accepts local files, memory buffers or URL's files as input sources. For big files, I needed to display only some elements. So, instead of displaying DOM nodes on item expanding as Frank Ale do it in his article 'How to load a tree view with a large XML file', I prefer filtering the XML input source by element's counters like StartElement and EndElement.

Implementation

To incorporate this into your app, you just need to incorporate the XmlBrowser ActiveX in your project. The ActiveX must be initialized by calling Initialize and destroyed by calling the Terminate method. If your (C++) project is already linked with the Xerces library and already call the XMLPlatformUtils::Initialize and XMLPlatformUtils::Terminate, you don't need to call the ActiveX methods.

As described in the CXmlBRowser::Parse method, the ActiveX inverts the both counters. Counters are deactivated when they are equals to -1.

// little inversion, in case of error
if(m_nStartElement != -1 && m_nEndElement != -1 
        && m_nEndElement < m_nStartElement)
{
    const long nInverse = m_nStartElement;

    m_nStartElement = m_nEndElement;

    m_nEndElement = nInverse;
}

The tree items are built in the HandlerBase implementation. startElement creates a new child item, endElement permits to retrieve the parent one.

void CBrowserHandler::startElement(const XMLCh* const name,
                AttributeList&  attributes)
{
    m_nCurrentIndex++;

    ...
		
    m_hCurrentRecord = TreeView_InsertItem(
        GetBrowser()->m_ctlSysTreeView32.m_hWnd,
        &insert);  
void CBrowserHandler::endElement(const XMLCh* const name)
{
    ...
    if(m_hCurrentRecord !=NULL && m_hCurrentRecord != TVI_ROOT)
        m_hCurrentRecord = TreeView_GetParent(
            GetBrowser()->m_ctlSysTreeView32.m_hWnd,
            m_hCurrentRecord);
}

Other parameters like ValidationScheme, DoNamespaces etc. are available. For more information on these parameters, pleaser refer to the Xml Apache Group Documentation. Sources and documentation can be downloaded on http://xml.apache.org site.

Please don't send emails but post here if you have any questions regarding this article.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Philippe Bonneau
Founder EBSYS
France France
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionhow to use EbXmlBrowser.dllmemberwyoo7 Mar '05 - 21:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 7 Aug 2002
Article Copyright 2002 by Philippe Bonneau
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid