Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Parsing xml... I know, I know

  1. #1

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Resolved [RESOLVED] [2005] Parsing xml... I know, I know

    I have an xml file structured thusly:

    xml Code:
    1. <?xml version="1.0" encoding="us-ascii" ?>
    2. <signaturelist>
    3.     <signature>
    4.         <name>Final Fantasy VI Advance</name>
    5.         <editor>FFVIAdvance.dll</editor>
    6.         <sram>
    7.             <start>7936</start>
    8.             <length>32</length>
    9.             <string>46494E414C2046414E544153592056492020202020414456414E434520202020</string>
    10.         </sram>
    11.         <vba>
    12.             <start>4</start>
    13.             <length>16</length>
    14.             <string>464636414456414E43450000425A3645</string>
    15.         </vba>
    16.     </signature>
    17.     <signature>
    18.         <name>Castlevania: Circle of the Moon</name>
    19.         <editor>CastlvaniaCotM.dll</editor>
    20.         <sram>
    21.             <start>0</start>
    22.             <length>11</length>
    23.             <string>44524143554C4120414742</string>
    24.         </sram>
    25.         <vba>
    26.             <start>4</start>
    27.             <length>16</length>
    28.             <string>44524143554C41204147423141414D45</string>
    29.         </vba>
    30.     </signature>
    31. </signaturelist>

    If the structure is wrong then let me know, I made it using Expression Web.

    I have looked at examples of parsing xml files and have the following code:

    vb.net Code:
    1. Dim m_xmld As New Xml.XmlDocument
    2.         m_xmld.LoadXml(My.Resources.signatures)
    3.  
    4.         Dim start_nodes As Xml.XmlNodeList = m_xmld.GetElementsByTagName("start")
    5.         Dim length_nodes As Xml.XmlNodeList = m_xmld.GetElementsByTagName("length")
    6.         Dim string_nodes As Xml.XmlNodeList = m_xmld.GetElementsByTagName("string")
    7.  
    8.         Dim i As Integer = 0
    9.         Do
    10.             If Read.HexString(CInt(start_nodes(i).Value), CInt(length_nodes(i).Value)) = string_nodes(i).Value Then
    11. ' extra code here
    12. i += 1
    13. End If
    14. Loop While i < start_nodes.Count

    basically the HexString function will read bytes from my internal buffer starting at "start" and reading "length" bytes. It then returns a string containing the bytes read. If it is equal to "string" then the correct signature is read.

    My problem:
    I cannot figure out how to know if I am in the "sram" or "vba" node or even which signature I am reading from (so I can get the value of "name" and "editor"). I could count the number of signatures I have read through but they will not be in any concrete order.

    Previously, I have used a line delimited text file with each signature on it's own line. Each property was seperated by a "|" character and I would split the line and check the signature like that.

    I wanted to instead use xml. Thanks, Troy.
    Prefix has no suffix, but suffix has a prefix.

  2. #2
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    Re: [2005] Parsing xml... I know, I know

    Since you've loaded the whole XML into a XmlDocument object why not use XPATH queries to directly read the part you're looking for?
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  3. #3

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: [2005] Parsing xml... I know, I know

    I has posted an update before your response but it did not show up. Basically I am reading the file and comparing certain byte strings within the file. If they match then the file is good. There is no way to tell exactly which element I am looking for so all the elements (sram and vba) must be checked.

    Since my update did not show up I will resolve this thread. Thank you for your help Mr. No.
    Prefix has no suffix, but suffix has a prefix.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width