Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

Industry Leaders: 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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

609 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