?
Solved

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

Posted on 2004-05-02
5
Medium Priority
?
936 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

800 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