fast XML file scan......

Hello,

I am relatively new to XML. I have a project where I need to validate a scanned code against a file. The project is a Windows CE pproject using Compact Framework 1.1. Currently the file is XML but it doesnt have to be.

I did it using an XML document and scanning through the nodes, it is pretty fast but not fast enough. The maximum number of elements it has to loop through is 3600 and that takes about 1.5-2 seconds. The customer wants it instantaneous.

Here is my code, I would appreciate any insight into a faster way to scan for these values. SQL CE is not an option.

'in a module so the object can be global to my application
      public rdr as XmlTextReader
        Public xmlDoc As New XmlDocument()
        Public n As XmlNode
        Public n1 As XmlNode

        public found as Boolean = false


'search method

          ' Set n to the first  node.
            n = xmlDoc.DocumentElement.FirstChild
            Do While found = false
            ' Set n1 to the first child node (a  node).
            n1 = n.FirstChild
            Do While Not n1 Is Nothing
                    if n1.innertext = me.txtAutoCode.text
                        found = true
                        Exit Do
                    end if
                    n1 = n1.NextSibling()
            Loop
            n = n.NextSibling()
            If n Is Nothing Then Exit Do
            ' A blank line.
            Loop

 



Answer this question

fast XML file scan......

  • Bill Sullivan

    Try using XmlTextReader.
  • Sam Bent

    the reader itself is slower (not by much) on a CE device. What I ended up doing was loading the reader contents into an array up front, then doing a binary search on the array from then on when looking for values.

    was about 10 times faster than what I had :)

        


  • Ralf Kornmann

    Yes reader will be slower if you are loading the same file over and over again.  Caching it in custom memory structure then makes sense. But to be clear on XmlReader, if you are just loading one file only once then XmlReader will be a lot faster than XmlDocument since XmlDocument uses XmlReader, then builds a big tree of nodes.
  • fast XML file scan......