Hi Guys,

For the past 2 days i have been trying to come up with a simple solution for this problem, but i have turned up nothing so far.

basically i have a few fields in some html named:

vb.net Code:
  1. <input type="hidden" name="name1" value="value1">
  2. <input type="hidden" name="name2" value="value2">
  3. <input type="hidden" name="name3" value="value3">

i can grab the name fields fine and also store them in an .xml file, but when i try to get the value fields and place them like:

vb.net Code:
  1. <field>name1}{value1</field>

I'm getting errors, basically because the name fields have 13 and the value fields have 14, so the numbers don't match up.

my code below is a bit clumsy, i have deleted/undeleted so much:

vb.net Code:
  1. '// This is the pattern we want to match the hidden fields
  2.         Dim fieldSource As New Regex("(?<=""hidden"" name="").*?(?="")", _
  3.                      RegexOptions.IgnoreCase Or RegexOptions.Singleline)
  4.  
  5.         '// [Hidden Name Fields Count] This hold all the matches returned
  6.         Dim classMatches As MatchCollection = fieldSource.Matches(HTML)
  7.  
  8.         '// Return the number of hidden fields
  9.         Dim numHiddenreFields As Integer = classMatches.Count
  10.  
  11.         '// File location
  12.         Dim file As String = "Debug/xForm(4)-(file).xml"
  13.  
  14.         '// The XmlTextWriter that will build the XML file
  15.         Dim myX As New Xml.XmlTextWriter(file, System.Text.Encoding.UTF8)
  16.  
  17.         '// Add a few extra options to the XML
  18.         With myX
  19.             .Formatting = Formatting.Indented
  20.             .Indentation = 3
  21.  
  22.             '// Write an element (this one is the root)
  23.             myX.WriteStartDocument()
  24.             myX.WriteStartElement("hiddenfileFields")
  25.  
  26.             myX.WriteStartElement("hiddenfileChallenge")
  27.             myX.WriteStartElement("hiddenfileChallengeField")
  28.             myX.WriteValue(ChallengeField)
  29.             myX.WriteEndElement()
  30.             myX.WriteEndElement()
  31.  
  32.             '// Use a for loop to go through tha array values
  33.             For Z As Integer = 0 To numHiddenreFields - 1
  34.  
  35.                 '1)
  36.                 '// Set up the regular expression
  37.                 Dim hiddenNames As New Regex("(?<=""hidden"" name="").*?(?="")", _
  38.                                      RegexOptions.IgnoreCase Or RegexOptions.Singleline)
  39.  
  40.                 '// This is an array of the files we don't want  
  41.                 Dim sourceNames As MatchCollection = hiddenNames.Matches(HTML)
  42.  
  43.  
  44.                 ' ''2)
  45.                 ' ''// Set up the regular expression
  46.                 'Dim hiddenValues As New Regex("(?<=<input type=""hidden"" name=""" & sourceNames(Z).ToString & """ value="").*?(?="")", _
  47.                 '                     RegexOptions.IgnoreCase Or RegexOptions.Singleline)
  48.  
  49.                 ''// Put all the values in a collection
  50.                 'Dim sourceValues As MatchCollection = hiddenValues.Matches(HTML)
  51.  
  52.                 'For Each sourceValues2 As Match In sourceValues
  53.                 '    MessageBox.Show(sourceValues2.ToString)
  54.                 'Next
  55.  
  56.                 '// Write the values to the xml file
  57.                 myX.WriteStartElement("reFields" & (Z))
  58.                 myX.WriteValue(sourceNames(Z).ToString)
  59.                 myX.WriteEndElement()
  60.  
  61.             Next
  62.  
  63.             '// Close up and end document
  64.             myX.WriteEndDocument()
  65.             myX.Close()
  66.  
  67.         End With

What i am thinking now, is if there was a way to get the "name" and "value" field with the 1 regular expression, instead of having to do the 2, would that be possible? or is there an easier way i could have done this?

my brain aches from trying to work this out lol

thanks for any help guys

Graham