; begin KiXgolfUDF
;
;!
Function WFP($)
Dim $LineIn,$InitialArray[0],$Counter,$TestResult,$TempArray[0],$Counter2,$Temp,$Temp2,$Tag,$Temp3[],$Start,$Letter,$Match
$Counter = 0
$Counter2 = 0
;Start by Breaking up the Initial File into an array to manage the contents
Open(1,$)
;;======Debug Here=========
Open (2,"ArrayOutput.txt",5)
WriteLine(2,"File Name = " + $ + @CRLF)
;;
$LineIn = Readline(1)
While @Error = 0
$InitialArray[$Counter] = Trim($LineIn)
$Counter = $Counter + 1
Redim Preserve $InitialArray[$counter]
$LineIn = Readline(1)
Loop
Close(1)
;;;===========Debug Here ===============
;For $counter = 0 to Ubound($InitialArray)
;
; Writeline(2, "Element " + $counter + " = " + $InitialArray[$Counter] + @CRLF)
;
;Next
;;;
;Look to see if the version tag is there
If $InitialArray[0] = '<?xml version="1.0"?>'
$TestResult = 0
Else
$TestResult = 1
EndIf
$InitialArray[0] = "" ;Clear the data so we can safely ignore it later
;;==============Debug Here ===============
Writeline(2, "Version tag test = " + $Testresult + @CRLF)
;;
;Parse out the Open and Close Tags
;Look at the Input string from the initial array and find the first <
For $Counter = 1 to Ubound($InitialArray)
;break out the string to look for multiple tags on a single line
For $Temp = 1 to Len($InitialArray[$Counter])
If SubStr($InitialArray[$counter],$Temp,1) = "<"
$Start = $Temp
While Substr($InitialArray[$Counter],$Temp,1) <> ">"
$Temp = $Temp + 1
Loop
Redim Preserve $TempArray[$Counter2]
$TempArray[$Counter2] = Substr($InitialArray[$Counter],$Start,($Temp +1) - $Start)
$Counter2 = $Counter2 + 1
EndIf
Next
Next
;;Debug Code
For $counter = 0 to Ubound($TempArray)
Writeline(2, "Element " + $counter + " = " + $TempArray[$Counter] + @CRLF)
Next
;Are there matching open and close tags
For $Counter = 0 to Ubound($TempArray)
;Find an Open Tag
If left($TempArray[$Counter],2) <> "</" AND left($TempArray[$Counter],2) <> 0
;Now we validate all the different conditions
;To Get it working in the most basic form
$Temp = Left(Substr($TempArray[$Counter],2),-1) ;This will give us the non tag characters to use for comparison
WriteLine(2,"Line that we are checking = " + $Temp +@CRLF) ;Debugging
;Check for same name tags within each other
$Temp2 = Ascan($Temparray,"</" + $Temp + ">",$Counter)
WriteLine(2,"value of tag in a tag = " +$Temp2+@crlf) ; debuggin
If Ascan($Temparray,"<"+$Temp+">",($counter + 1)) < $Temp2 And Ascan($Temparray,"<"+$Temp+">",($counter + 1)) > -1
$Tag = Ascan($Temparray,"<"+$Temp+">",($counter + 1))
WriteLine(2,"We found a value of "+$Tag+" less than the next close"+@crlf) ;debuggin
$TestResult = $TestResult | 1
EndIf
;Now we have to test to see if this is an attibute
If Instr($Temp," ")
If Instr($Temp,"=")
$Temp3 = Split($Temp,"=")
Writeline(2,"This is an Attribute, The Value after the = is " +$Temp3[1] +@CRLF) ;Debuggin
;Writeline(2,"This is the first value we are checking " + left($Temp3[1],1) + "and this is the second value " + Right($Temp3[1],1) + @CRLF) ; Debuggin
Writeline(2,"This is the first value we are checking " + left($Temp3[1],1) + "and this is the second value " + InstrRev($Temp3[1],CHR(34)) + @CRLF)
;If left($Temp3[1],1) = CHR(34) and Right($Temp3[1],1) = CHR(34)
;;;This is the new LINE to be PUT into the stipped code
If Left($Temp3[1],1) = CHR(34) and InstrRev($Temp3[1],CHR(34)) > 1
WriteLine(2,"The attribute test Passed" + @CRLF) ;Debuggin
;Have to rewrite the value of $Temp to remove attibute fields
$Temp = Split($Temp3[0])[0]
Writeline(2,"New value of $Temp = " + $Temp + @CRLF)
$TestResult = $TestResult | 0
Else
$TestResult = $TestResult | 1
EndIf
EndIf
EndIf
;Check for invalid characters in the string
For $Counter2 = 0 to Len($Temp) -1
Redim Preserve $Temp3[$Counter2]
$Temp3[$Counter2] = Substr($Temp,$Counter2 +1,1)
Next
For each $Letter in $Temp3
Select
Case asc($Letter) = 45
Writeline(2,"Valid Character of " +$Letter+@CRLF); debuggin
Case asc($Letter) > 46 AND asc($letter) < 58
Writeline(2,"Valid Character of " +$Letter+@CRLF); debuggin
Case asc($letter) > 64 AND asc($letter) < 91
Writeline(2,"Valid Character of " +$Letter+@CRLF); debuggin
Case asc($letter) > 96 and asc($letter) < 123
Writeline(2,"Valid Character of " +$Letter+@CRLF); debuggin
Case asc($letter) = 32
Case 1
Writeline(2,"inValid Character of " +$Letter+@CRLF); debuggin
$TestResult = $TestResult | 1
EndSelect
Next
;Finally is there corresponding open and close tags
$Temp2 = Ascan($TempArray,"</"+ $Temp + ">",$Counter)
If $Temp2 > -1
$TempArray[$Counter] = 0
WriteLine(2,"Found a proper Close tag. Clearing the element: "+$counter+@CRLF)
$TempArray[$Temp2] = 0
WriteLine(2,"And The closing tag is element: "+$Temp2+@CRLF)
Else
$Temp2 = Ascan($TempArray,"<" + Left($Temp,-1) + "/>")
If $Temp2 > -1
$TempArray[$Temp2] = 0
Writeline(2,"Found the 'orders/' tag. Clearing element: "+$Temp2+@CRLF)
Else
$TestResult = $TestResult | 1
Writeline(2,"Failue on open and close tags"+@CRLF)
EndIf
EndIf
; If Ascan($TempArray,"</" + $Temp + ">",$Counter) > -1 OR Ascan($TempArray,"<" + Left($Temp,-1) + "/>") > -1
;
; $TestResult = $TestResult | 0
; Else
; $TestResult = $Testresult | 1
; EndIf
EndIf
Next
If Instr(Join($TempArray),"<")
$TestResult = $TestResult | 1
EndIf
Writeline(2,Join($TempArray)+@CRLF)
If $TestResult = 0
$WFP = "well-formed"
Else
$WFP = "non well-formed"
EndIf
;;================= Debug Here ==============
Close(2)
;;
EndFunction
;!
;!
; end KiXgolfUDF