Solved

Find XML value quickly- without too much overhead and fuss.

Posted on 2004-05-02
5
930 Views
Last Modified: 2012-06-27
This is part of my XML file:-
<?xml version="1.0" ?>
- <Timeline Name="50144595" Path="E:\source\Server\Timelines\50144595.tml" Checksum="239820" ProclaimVersion="1.5" BitmapItems="2" VideoItems="1" InfoboxItems="1" ScrollItems="1">

I am using it as a INI which will be accessed every few minutes for certain values.  However, I have been studying Xpath and few other ways, but what I really want is a simple VB.NET function like we used to do when reading INI files in VB6.

I was to check the "Checksum" value without going through a collection, I would like to call it like value=GetChecksumFromXML(filename)

It it is ciritical that I can do this quickly without too much processor activity as it is part of a smooth running display.  Just a quick grab, but without using collections any other iterator type routines.

Regards
Dave
Posted Sunday Afternoon in UK.
0
Comment
Question by:DaveRowland
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Author Comment

by:DaveRowland
ID: 10971273
Anyone?  appreciate a quick answer.. increased points
0
 
LVL 6

Expert Comment

by:danths
ID: 10972665
Did you consider putting your entry in app.config?
and then http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpgrfaccessingappsettingssection.asp

Internally they will have to go thru an iterator,  however the interface will be easier for you.

0
 
LVL 1

Author Comment

by:DaveRowland
ID: 10973033
nope.. no good.  I refer to INI but they are not app settings, they are changing values by external programs for media purposes.. dont ask.  But I am currently implementing XPath method, but would still like to be able to address "directly" a XML file.

In other words,  

1:  Find "Timeline/Checksum" in fred.xml
2:  Returns 239820 to the function that called it.

I don't want to Load XML file, Prepare pointers etc., then "do loop" it to find Checksum and then return a value back.  So much overhead, must be a way of finding a value quickly.
0
 
LVL 6

Accepted Solution

by:
danths earned 500 total points
ID: 10973672
Not sure what your objective is? You would want to use an XML file for setting but assume that parsing an XML file is an overhead. What type of parser are you planning to use, a DOM or SAX. Did you go thru the basics of understanding what they are and when and how to use them? How and why did you discard them as overhead. Did you do some profiling of the code?

Lets completely forget about using XML for such things? You consider getting an value in probably VB6 INI would be fast enough, if so would you really put such dynamic values in an INI? If not why are you considering an XML for this?
Any how I think you should revise what and why you are doing? I am still posting a function that I often use for a DOM based ( XMLDcoument) parsing


Protected Function GetElementValue(ByVal xmlDoc As XmlDocument, _
                                            ByVal elementPattern As String) As Collection
            Dim oXMLNode As XmlNode
            Dim oXMlAttr As XmlAttribute
            Dim oXMLNodeList As XmlNodeList
            Dim colValue As New Collection
            Dim iCounter As Integer
            Dim strValue As String


            'Initialize the iCounter to 1
            iCounter = 1

            Try
                oXMLNodeList = xmlDoc.SelectNodes(elementPattern)
            Catch e As Exception
                If mLogger.IsFatalEnabled Then mLogger.Fatal(e.ToString)
            End Try

            If (oXMLNodeList.Count > 0) Then
                For Each oXMLNode In oXMLNodeList
                    iCounter = 1
                    If (oXMLNode.NodeType = XmlNodeType.Element And oXMLNode.HasChildNodes) Then

                        strValue = oXMLNode.ChildNodes.Item(iCounter - 1).Value

                        If Not (strValue Is Nothing) Then
                            colValue.Add(oXMLNode.ChildNodes.Item(iCounter - 1).Value)
                        End If

                    End If
                    strValue = Nothing
                Next
            End If

            GetElementValue = colValue

        End Function

        Protected Function GetAttributeValue(ByVal xmlDoc As XmlDocument, _
                                            ByVal elementPattern As String, _
                                            ByVal vAttrPattern As String) As Collection
            Dim oXMLNode As XmlNode
            Dim oXMlAttr As XmlAttribute
            Dim oXMLNodeList As XmlNodeList
            Dim colValue As New Collection
            Dim iCounter As Integer
            Dim strAttrValue As String

            iCounter = 1
            'This should return only one value
            Try
                oXMLNodeList = xmlDoc.SelectNodes(elementPattern)
                'If mLogger.IsDebugEnabled Then mLogger.Debug("XML Pattern Finder: " & vPattern & " Count: " & oXMLNodeList.Count)

                If (oXMLNodeList.Count > 0) Then
                    For Each oXMLNode In oXMLNodeList
                        If (oXMLNode.NodeType = XmlNodeType.Element) Then

                            strAttrValue = ""
                            If Not (oXMLNode.Attributes.GetNamedItem(vAttrPattern) Is Nothing) Then
                                strAttrValue = oXMLNode.Attributes.GetNamedItem(vAttrPattern).Value
                            End If

                            If (Len(strAttrValue) > 0) Then
                                ' colValue.Add(strAttrValue, CStr(iCounter))
                                colValue.Add(strAttrValue)
                                'iCounter = iCounter + 1
                            End If
                        End If
                    Next
                    GetAttributeValue = colValue
                End If
            Catch e As Exception
                If mLogger.IsFatalEnabled Then mLogger.Fatal(e.ToString)
            End Try
            GetAttributeValue = colValue
        End Function
0
 
LVL 1

Author Comment

by:DaveRowland
ID: 10975984
Thanks for the code.  I am working my way through it and understanding it.

Basically Danths, I am converting my old package from VB6 to VB.NET and trying to get the code fairly good on the way, it is a visual display system with moving messages, videos and so forth.  It get's it's "timeline" insutrctions from a INI which I am converting to XML.  These XML files control when certain things appear on the screen, previously I used to load the whole INI-sequence into the display app and just run through it.  However there is a little bit more to that, like when updates happen, detecting changes etc.

I have spent some of last year learning new concepts of XML and VB.NET but with so many changes, it is hard to keep on top of all the depth that is now in the programming environments.

The XML system was a good approach as later on I can use the Editor and create ASP.NET version of the editor and so forth that ties in and writes a XML which then can work over IP or even store it to FTP and deploy.

I have tested a little bit of the code above and can see how to use it.  thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question