newbie27
asked on
xml split
Hello Folks,
I have set of records being returned as Ajax response, I am unable to split it by records and display one after the other, it is currently getting displayed all in one line.
Can someone please help me here.
Thanks
Sam
I have set of records being returned as Ajax response, I am unable to split it by records and display one after the other, it is currently getting displayed all in one line.
Can someone please help me here.
Thanks
Sam
ASKER
I am getting results like this
The 5 Paths to PersuasionThe 5 Paths to Persuasion
it should rather be like this ... please help..
The 5 Paths to Persuasion
The 5 Paths to Persuasion
The 5 Paths to PersuasionThe 5 Paths to Persuasion
it should rather be like this ... please help..
The 5 Paths to Persuasion
The 5 Paths to Persuasion
ASKER
hello dosth,
thanks for your comment, I am already doing that in my XMLField function but unable to figure how to break it soon I process the first record .....
please can someone help?
thanks
thanks for your comment, I am already doing that in my XMLField function but unable to figure how to break it soon I process the first record .....
please can someone help?
thanks
'###############################################################################
Function XMLField(ByVal XMLText, FieldName, ire)
' 2007-02-07: Completely revamped and revised. Should work version!
'
Dim fieldlist, fl
Dim CurrentText, FieldData
CurrentText = XMLText
FieldName = Replace(FieldName, "\", "/") '"
fieldlist = Split(FieldName, "/")
For each fl in fieldlist
FieldData = ExtractXMLField(CurrentText, fl, ire)
CurrentText = FieldData
Next
' Tidy; but not always a good idea!
If ire = False then
FieldData = Replace(FieldData, "<![CDATA[", "")
FieldData = Replace(FieldData, "]]>", "")
End If
XMLField = FieldData
End Function
'###############################################################################
Function ExtractXMLField(ByVal XMLText, ElementName, ire)
' 2007-02-07'
Dim StartPointer,FieldDelimiter,FieldName,StartTag,EndTag,pos1,pos2,FieldData
Dim tmpTags, tmpAttr, tmpData
StartPointer = 1
FieldDelimiter = chr(28)
FieldName = ElementName
If Instr(1, XMLText, "<" & FieldName & " ", 1) > 0 Then
' you know the Element has an attribute
StartTag = "<" & FieldName & " "
EndTag = "</" & Replace(FieldName, " ", "") & ">"
' This should find short version elements eg <br /> without breaking the rest of the script. Hah!!
If instr(1, XMLText, EndTag, 1) < 1 Then
EndTag = ">"
End If
Else
StartTag = "<" & FieldName & ">"
EndTag = "</" & FieldName & ">"
End If
'msg("Tags: [" & StartTag & "] [" & EndTag & "]")
pos1 = 0
Do While (pos1 < Len(XMLText))
pos1 = instr(StartPointer, XMLText, StartTag, 1)
if pos1 = 0 Then exit Do
pos2 = instr(pos1, XMLText, EndTag, 1)
if pos1 > 0 AND pos1 < pos2 then
' what we normally expect
tmpTags = Mid(XMLText, pos1, (pos2 + Len(EndTag)) - Pos1)
if Right(StartTag, 1) = " " Then
tmpAttr = Mid(tmpTags, len(StartTag)+1, Instr(tmpTags, ">")-len(StartTag))
if Right(tmpAttr, 1) = ">" Then tmpAttr = Trim(Left(tmpAttr, Len(tmpAttr)-1))
if Right(tmpAttr, 1) = "/" Then tmpAttr = Trim(Left(tmpAttr, Len(tmpAttr)-1))
Attr = Attr & tmpAttr & FieldDelimiter
End If
tmpData = Replace(tmpTags, StartTag & tmpAttr, "",1 ,-1, 1)
tmpData = Replace(tmpData, EndTag, "", 1, -1, 1)
if left(tmpData, 1) = ">" Then tmpData = Trim(Right(tmpData, Len(tmpData)-1))
if Right(tmpData, 1) = "/" Then tmpData = Trim(Left(tmpData, Len(tmpData)-1))
If ire = true then
FieldData = FieldData & tmpTags & FieldDelimiter
Else
FieldData = FieldData & tmpData & FieldDelimiter
End If
StartPointer = pos2 + Len(EndTag)
ElseIf pos1 <= 0 Or pos2 <= 0 Then
' The value is either empty or meaningless
Exit Do
End if
Loop
If Right(FieldData, 1) = FieldDelimiter Then FieldData = Left(FieldData, Len(FieldData)-1)
If Right(Attr, 1) = FieldDelimiter Then Attr = Left(Attr, Len(Attr)-1)
ExtractXMLField = FieldData
End Function
'###############################################################################
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Assuming
x = <resultfields id="1">
<id>1</id>
<score>100</score>
<titleurl><![CDATA[http://213.253.134.26/xmla/xml_display.asp?K=9780446695909&M=1&DC=2&MW=3&DBM=melia
&Q=(uk_dcode contains (26846))&ST_01=Robert B Miller&SF_01=CAUTHOR]]></t itleurl>
<fv_ref_no>9780446695909</ fv_ref_no>
</resultfields><resultfields id="2">
<id>2</id>
<score>100</score>
<titleurl><![CDATA[http://213.253.134.26/xmla/xml_display.asp?K=9780446532396&M=2&DC=2&MW=3&DBM=melia
&Q=(uk_dcode contains (26846))&ST_01=Robert B Miller&SF_01=CAUTHOR]]></t itleurl>
<fv_ref_no>9780446532396</ fv_ref_no>
</resultfields>
I am getting
p= 1 100 9780446695909 2 100 9780446532396
x = <resultfields id="1">
<id>1</id>
<score>100</score>
<titleurl><![CDATA[http://213.253.134.26/xmla/xml_display.asp?K=9780446695909&M=1&DC=2&MW=3&DBM=melia
&Q=(uk_dcode contains (26846))&ST_01=Robert B Miller&SF_01=CAUTHOR]]></t
<fv_ref_no>9780446695909</
</resultfields><resultfields id="2">
<id>2</id>
<score>100</score>
<titleurl><![CDATA[http://213.253.134.26/xmla/xml_display.asp?K=9780446532396&M=2&DC=2&MW=3&DBM=melia
&Q=(uk_dcode contains (26846))&ST_01=Robert B Miller&SF_01=CAUTHOR]]></t
<fv_ref_no>9780446532396</
</resultfields>
I am getting
p= 1 100 9780446695909 2 100 9780446532396
ASKER
there is some white space between these 2 records
x = GetXML(rUrl)
parts = Split(XMLField(x, "resultfields", true), "|")
For each p in parts
k=split(XMLField(p, "resultfields", False), chr(28))
For each p in parts
xmlAuthorName = "<a href='#'>" & XMLField(x, "fv_ctitle", False) & "</a><br>"
response.write xmlAuthorName
next
x = GetXML(rUrl)
parts = Split(XMLField(x, "resultfields", true), "|")
For each p in parts
k=split(XMLField(p, "resultfields", False), chr(28))
For each p in parts
xmlAuthorName = "<a href='#'>" & XMLField(x, "fv_ctitle", False) & "</a><br>"
response.write xmlAuthorName
next
ASKER
please ignore the above, that has got posted accidentally...
there is some white space between these 2 records, i probably have to split it again by
split(XMLField(p, "resultfields", False), chr(28))
can i use like this ?
x = GetXML(rUrl)
parts = Split(XMLField(x, "resultfields", true), "|")
For each p in parts
k=split(XMLField(p, "resultfields", False), chr(28)) ' can i use something like this here?
For each k in parts
xmlAuthorName = "<a href='#'>" & XMLField(x, "fv_ctitle", False) & "</a><br>"
next
response.write xmlAuthorName
next
there is some white space between these 2 records, i probably have to split it again by
split(XMLField(p, "resultfields", False), chr(28))
can i use like this ?
x = GetXML(rUrl)
parts = Split(XMLField(x, "resultfields", true), "|")
For each p in parts
k=split(XMLField(p, "resultfields", False), chr(28)) ' can i use something like this here?
For each k in parts
xmlAuthorName = "<a href='#'>" & XMLField(x, "fv_ctitle", False) & "</a><br>"
next
response.write xmlAuthorName
next
ASKER
this seems to have worked....
x = GetXML(rUrl)
'response.write(XMLField(x , "resultfields", true))
parts = Split(XMLField(x, "resultfields", true), "|")
parts = split(XMLField(x, "resultfields", False), chr(28)) ' can i use something like this here?
For each p in parts
response.write "p=" & p & "<br>"
xmlAuthorName = xmlAuthorName & "<a href='#'>" & XMLField(x, "fv_ctitle", False) & "</a>"
next
response.write xmlAuthorName
x = GetXML(rUrl)
'response.write(XMLField(x
parts = Split(XMLField(x, "resultfields", true), "|")
parts = split(XMLField(x, "resultfields", False), chr(28)) ' can i use something like this here?
For each p in parts
response.write "p=" & p & "<br>"
xmlAuthorName = xmlAuthorName & "<a href='#'>" & XMLField(x, "fv_ctitle", False) & "</a>"
next
response.write xmlAuthorName
just try with trim
x = GetXML(rUrl)
parts = Split(trim(XMLField(x, "resultfields", true)), "|")
For each p in parts
xmlAuthorName = "<a href='#'>" & XMLField(x, "fv_ctitle", False) & "</a><br>"
response.write xmlAuthorName
next
x = GetXML(rUrl)
parts = Split(trim(XMLField(x, "resultfields", true)), "|")
For each p in parts
xmlAuthorName = "<a href='#'>" & XMLField(x, "fv_ctitle", False) & "</a><br>"
response.write xmlAuthorName
next
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
hello neeraj,
thanks for your comment
could you please visit here
http://213.253.134.26/melia/display.asp?K=9780446695909&aub=Robert%20B.%20Miller&m=1&dc=2
thanks for your comment
could you please visit here
http://213.253.134.26/melia/display.asp?K=9780446695909&aub=Robert%20B.%20Miller&m=1&dc=2
ASKER
this still has not been resolved folks,
i am using
x = GetXML(rUrl)
parts = Split(XMLField(x, "resultfields", true), "|")
parts = split(XMLField(x, "resultfields", False), chr(28))
For each p in parts
xmlAuthorName = xmlAuthorName & "<a href=http://213.253.134.26/melia/display.asp?k=" & XMLField(x, "fv_barcode", False) & "&AUB=" & XMLField(x, "fv_vx_first_name", False) & ">" & XMLField(x, "fv_ctitle", False) & "</a>"
next
response.write xmlAuthorName
i am using
x = GetXML(rUrl)
parts = Split(XMLField(x, "resultfields", true), "|")
parts = split(XMLField(x, "resultfields", False), chr(28))
For each p in parts
xmlAuthorName = xmlAuthorName & "<a href=http://213.253.134.26/melia/display.asp?k=" & XMLField(x, "fv_barcode", False) & "&AUB=" & XMLField(x, "fv_vx_first_name", False) & ">" & XMLField(x, "fv_ctitle", False) & "</a>"
next
response.write xmlAuthorName
ASKER
dosth,
trim did not work either ...
because it has a space/or some character between the records which is why i was thinking to split by chr(28), it has worked in the past...
trim did not work either ...
because it has a space/or some character between the records which is why i was thinking to split by chr(28), it has worked in the past...
ASKER
Guys,
this is somehow working but very dirty way ...
can you please help me in cleaning the attached code a bit please...
this is somehow working but very dirty way ...
can you please help me in cleaning the attached code a bit please...
x = GetXML(rUrl)
parts = split(XMLField(x, "resultfields", False), chr(28))
For each p in parts
st = split(XMLField(x, "fv_barcode", False),chr(28))
nm = split(XMLField(x, "fv_vx_first_name", False),chr(28))
tit = split(XMLField(x, "fv_ctitle", False),chr(28))
for each s in st
recId = s
next
for each j in nm
recname = j
next
for each t in tit
retitle = t
next
'response.write "<a href=""http://213.253.134.26/melia/display.asp?k=" & s &
response.write "<a href=""http://213.253.134.26/melia/display.asp?k=" & recId & "&AUB=" & recname & """>" & retitle & "</a><br>"
next
ASKER
Guys,
I had to understand more about the XML functions I was using to make it right, I have learned it now and it was so simple in the first place really...
all sorted now...thanks for your help anyways !
I had to understand more about the XML functions I was using to make it right, I have learned it now and it was so simple in the first place really...
all sorted now...thanks for your help anyways !
RemoteServer = "http://213.253.134.26"
rURL = RemoteServer & "/xmla/xml_results.asp?dbm=melia" & "&AUB=" & sName & "&"
x = GetXML(rUrl)
parts = split(XMLField(x, "resultfields", False), chr(28))
For each p in parts
response.write "<a href=""http://213.253.134.26/melia/display.asp?k=" & XMLField(p, "fv_barcode", False) & "&AUB=" & XMLField(p, "fv_vx_first_name", False) & """>" & XMLField(p, "fv_ctitle", False) & "</a><br>"
next
ASKER
------------
x = GetXML(rUrl)
x = GetXML(rUrl)
parts = Split(XMLField(x, "resultfields", true), "|")
For each p in parts
xmlAuthorName = "<a href='#'>" & XMLField(x, "fv_ctitle", False) & "</a><br>"
response.write xmlAuthorName
next
Open in new window