Extract String - Posted (1026 Views)
Average Member
kolucoms6
Posts: 845
845
Code:

<ErrorName>Lead Import Error.</ErrorName>

I want to pull out everything which appears between <ErrorName> and
</ErrorName>.
How to do it in asp/vbscript ?<
 Sort direction, for dates DESC means newest first  
 Page size 
Posted
Support Moderator
Podge
Posts: 3776
3776
You will need to use a regex similar to the one of this page - http://www.regular-expressions.info/examples.html

i.e.
Code:
<ErrorName\b[^>]*>(.*?)</ErrorName>
<
Posted
Average Member
kolucoms6
Posts: 845
845
regex doesnt look easy ? :-(<
Posted
Average Member
kolucoms6
Posts: 845
845
My entire string looks like this :

Code:

st="<?xml version="1.0" encoding="utf-8" ?> - <returnMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.abcsite.com/">  <ErrorName>Success</ErrorName>   <ErrorDescription>Approved - Ready to be assigned to Order</ErrorDescription>  <LeadID>13498919</LeadID>   <ClientAvailable>true</ClientAvailable>   </returnMessage>"

From above line or string, I want to Extract all which appears between

<ErrorName> and </ErrorName>.
I tried

<ErrorName\b[^>asdsad</ErrorName>

and it works... but how to from that string ?<
Posted
Support Moderator
Podge
Posts: 3776
3776
Fixed your closing code tag.
Can you post the asp code you are using to test the regex ?<
Posted
Average Member
kolucoms6
Posts: 845
845
Code:


<%

Option Explicit

Dim url
url = "http://<<domainname>>/Suppliers/WebServices/InsertLeads.asmx/InsertLead"

Private Function InsertLead(SupplierId, SupplierPassword, FirstName, LastName, EmailAddress, CoAppFirstName, CoAppLastName, Address, City, State, PostalCode, HomePhone, WorkPhone, WorkPhoneExt, CurrentEmployer, YearsThere, Income, BestCallTime, OriginalLeadDate, ExternalLeadID, IPAddress, ExtraFields)
Dim queryString
queryString = "SupplierID=" & SupplierId
queryString = queryString & "&SupplierPassword=" & SupplierPassword
queryString = queryString & "&FirstName=" & FirstName
queryString = queryString & "&LastName=" & LastName
queryString = queryString & "&EmailAddress=" & EmailAddress
queryString = queryString & "&CoAppFirstName=" & CoAppFirstName
queryString = queryString & "&CoAppLastName=" & CoAppLastName
queryString = queryString & "&Address=" & Address
queryString = queryString & "&City=" & City
queryString = queryString & "&State=" & State
queryString = queryString & "&PostalCode=" & PostalCode
queryString = queryString & "&HomePhone=" & HomePhone
queryString = queryString & "&WorkPhone=" & WorkPhone
queryString = queryString & "&WorkPhoneExt=" & WorkPhoneExt
queryString = queryString & "&CurrentEmployer=" & CurrentEmployer
queryString = queryString & "&YearsThere=" & YearsThere
queryString = queryString & "&Income=" & Income
queryString = queryString & "&BestCallTime=" & BestCallTime
queryString = queryString & "&OriginalLeadDate=" & OriginalLeadDate
queryString = queryString & "&ExternalLeadID=" & ExternalLeadID
queryString = queryString & "&IPAddress=" & IPAddress
queryString = queryString & "&ExtraFields=" & ExtraFields
Dim httpReq
Set httpReq = CreateObject("msxml2.serverxmlhttp.4.0")
httpReq.Open "GET", url & "?" & queryString, false
httpReq.Send
Response.write "<input type=hidden value="& queryString & ">" & "<br><br><br>"
Set InsertLead = httpReq
End Function

Public Sub Main()
Dim req
Set req = InsertLead("22525", "iopuat4n", "Joe", "Bloggs","joebloggs@somewhere.com", "Fred", "Smith", "123 High Street", "Springfield", "WA", "12345", "1231234399", "1231234399", "123", "ACME", "3", "", "", "5/26/2008", "324324", "", "DebtAmount=100000")
' Response.write Mid(req.ResponseText,Instr(req.ResponseText,"<ErrorName>"),Instr(req.ResponseText,"</ErrorName>")-1) & "<br><br>"
Response.write "<ErrorName\b[^>asdsad</ErrorName>"
' Response.write req.ResponseText & "<br><br>"

End Sub

Call Main()

%>



<
Posted
Support Moderator
Podge
Posts: 3776
3776
This works for me.
Code:
<%

StringToSearch = "<?xml version=""1.0"" encoding=""utf-8"" ?> - <returnMessage xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://www.abcsite.com/""> <ErrorName>Success</ErrorName> <ErrorDescription>Approved - Ready to be assigned to Order</ErrorDescription> <LeadID>13498919</LeadID><ClientAvailable>true</ClientAvailable> </returnMessage>"

Set RegularExpressionObject = New RegExp

With RegularExpressionObject
.Pattern = "<ErrorName\b[^>]*>(.*?)</ErrorName>"
.IgnoreCase = True
.Global = True
End With

Set expressionmatch = RegularExpressionObject.Execute(StringToSearch)

If expressionmatch.Count > 0 Then
For Each expressionmatched in expressionmatch
Response.Write "<B>" & expressionmatched.Value & "</B> was matched at position <B>" & expressionmatched.FirstIndex & "</B><BR>"
Next

Else
Response.Write "<B>" & RegularExpressionObject.Pattern & "</B> was not found in the string: <B>" & StringToSearch & "</B>."
End If

Set RegularExpressionObject = nothing
%>
<
 
You Must enter a message