Link to home
Create AccountLog in
Avatar of newbie27
newbie27Flag for United Kingdom of Great Britain and Northern Ireland

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
Avatar of newbie27
newbie27
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

ASP script
------------

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      
x = xml file below
-------------------
<?xml version="1.0"?>
 
<resultscollection>
 
<resultsetinformation>
 
<search_terms>Robert B Miller</search_terms>
 
<documentstart>1</documentstart>
 
<documentend>2</documentend>
 
<documentcount>2</documentcount>
 
<pagelength>15</pagelength>
 
<lastpage>1</lastpage>
 
</resultsetinformation>
 
<sessioninfo>
 
<querystring><![CDATA[/xmla/xml_results.asp?dbm=melia&AUB=Robert%20B.%20Miller&Miller,RobertB.&Q=(uk_dcode
 
 contains (26846))]]></querystring>
 
<prop><![CDATA[TAG=&CID=&PGE=]]></prop>
 
</sessioninfo>
 
<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]]></titleurl>
 
<fv_author id="1">Robert B. Miller</fv_author>
 
<fv_author id="2">Gary A. Williams</fv_author><fv_barcode>9780446695909</fv_barcode>
 
<fv_contributor id="1">Robert B. Miller (author)</fv_contributor>
 
<fv_contributor id="2">Gary A. Williams (author)</fv_contributor><fv_ctitle>The 5 Paths to Persuasion
 
</fv_ctitle>
 
<fv_dewey>658.45</fv_dewey>
 
<fv_edition>New edition</fv_edition>
 
<fv_format>Paperback</fv_format>
 
<fv_format_simple_code id="1">P</fv_format_simple_code>
 
<fv_format_simple_code id="2">BP</fv_format_simple_code><fv_imprint>Time Warner International</fv_imprint
 
>
 
<fv_isbn>0446695904</fv_isbn>
 
<fv_jacket>/jackets/m/978044/9780446695909.jpg</fv_jacket>
 
<fv_page_size>229 x 152 x 18</fv_page_size>
 
<fv_pub_year>2005</fv_pub_year>
 
<fv_ref_no>9780446695909</fv_ref_no>
 
<fv_sub_title>The Art of Selling Your Message</fv_sub_title>
 
<fv_total_pages>256</fv_total_pages>
 
<fv_uk_avail>Not available</fv_uk_avail>
 
<fv_uk_avail_code>OP</fv_uk_avail_code>
 
<fv_uk_pubdate>25 Nov 2005</fv_uk_pubdate>
 
<fv_uk_vat_price>9.99</fv_uk_vat_price>
 
<fv_vx_first_name>Miller, Robert B.</fv_vx_first_name>
 
<fv_vx_isbn>0446695904</fv_vx_isbn>
 
<fv_wco>ING</fv_wco>
 
</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]]></titleurl>
 
<fv_author id="1">Robert B. Miller</fv_author>
 
<fv_author id="2">Gary A. Williams</fv_author><fv_barcode>9780446532396</fv_barcode>
 
<fv_contributor id="1">Robert B. Miller (author)</fv_contributor>
 
<fv_contributor id="2">Gary A. Williams (author)</fv_contributor><fv_ctitle>The 5 Paths to Persuasion
 
</fv_ctitle>
 
<fv_dewey>658.45</fv_dewey>
 
<fv_edition>New title</fv_edition>
 
<fv_format>Hardback</fv_format>
 
<fv_format_simple_code id="1">H</fv_format_simple_code>
 
<fv_format_simple_code id="2">BH</fv_format_simple_code><fv_imprint>Time Warner International</fv_imprint
 
>
 
<fv_isbn>0446532398</fv_isbn>
 
<fv_jacket>/jackets/m/978044/9780446532396.jpg</fv_jacket>
 
<fv_page_size>229 x 152 x 24</fv_page_size>
 
<fv_pub_year>2005</fv_pub_year>
 
<fv_ref_no>9780446532396</fv_ref_no>
 
<fv_sub_title>The Art of Selling Your Message</fv_sub_title>
 
<fv_total_pages>240</fv_total_pages>
 
<fv_uk_avail>Not available</fv_uk_avail>
 
<fv_uk_avail_code>OP</fv_uk_avail_code>
 
<fv_uk_pubdate>01 Jul 2005</fv_uk_pubdate>
 
<fv_uk_vat_price>17.99</fv_uk_vat_price>
 
<fv_vx_first_name>Miller, Robert B.</fv_vx_first_name>
 
<fv_vx_isbn>0446532398</fv_vx_isbn>
 
</resultfields>
 
</resultscollection>

Open in new window

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
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

 '###############################################################################
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
 
'###############################################################################

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dosth
dosth
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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]]></titleurl>
<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]]></titleurl>
<fv_ref_no>9780446532396</fv_ref_no>
</resultfields>

I am getting

p= 1 100 9780446695909  2 100 9780446532396

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      
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      
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
                              
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
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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
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
                  
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...

Guys,
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 				 

Open in new window

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 !
  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 	

Open in new window