|
-
Jun 15th, 2007, 11:44 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] Parsing xml... I know, I know
I have an xml file structured thusly:
xml Code:
<?xml version="1.0" encoding="us-ascii" ?>
<signaturelist>
<signature>
<name>Final Fantasy VI Advance</name>
<editor>FFVIAdvance.dll</editor>
<sram>
<start>7936</start>
<length>32</length>
<string>46494E414C2046414E544153592056492020202020414456414E434520202020</string>
</sram>
<vba>
<start>4</start>
<length>16</length>
<string>464636414456414E43450000425A3645</string>
</vba>
</signature>
<signature>
<name>Castlevania: Circle of the Moon</name>
<editor>CastlvaniaCotM.dll</editor>
<sram>
<start>0</start>
<length>11</length>
<string>44524143554C4120414742</string>
</sram>
<vba>
<start>4</start>
<length>16</length>
<string>44524143554C41204147423141414D45</string>
</vba>
</signature>
</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:
Dim m_xmld As New Xml.XmlDocument
m_xmld.LoadXml(My.Resources.signatures)
Dim start_nodes As Xml.XmlNodeList = m_xmld.GetElementsByTagName("start")
Dim length_nodes As Xml.XmlNodeList = m_xmld.GetElementsByTagName("length")
Dim string_nodes As Xml.XmlNodeList = m_xmld.GetElementsByTagName("string")
Dim i As Integer = 0
Do
If Read.HexString(CInt(start_nodes(i).Value), CInt(length_nodes(i).Value)) = string_nodes(i).Value Then
' extra code here
i += 1
End If
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.
-
Jun 16th, 2007, 11:57 AM
#2
Fanatic Member
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 ...
-
Jun 16th, 2007, 03:31 PM
#3
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|