Solved

xml split

Posted on 2008-06-10
16
492 Views
Last Modified: 2008-06-10
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
0
Comment
Question by:newbie27
  • 12
  • 3
16 Comments
 
LVL 8

Author Comment

by:newbie27
ID: 21750394
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

0
 
LVL 8

Author Comment

by:newbie27
ID: 21750412
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
0
 
LVL 15

Expert Comment

by:dosth
ID: 21750433
0
 
LVL 8

Author Comment

by:newbie27
ID: 21750540
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

0
 
LVL 15

Accepted Solution

by:
dosth earned 250 total points
ID: 21750611
if you have this working
x = GetXML(rUrl)
parts = Split(XMLField(x, "resultfields", true), "|")

can you tell me what is the output of this

response.write(XMLField(x, "resultfields", true))
0
 
LVL 8

Author Comment

by:newbie27
ID: 21750656
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

0
 
LVL 8

Author Comment

by:newbie27
ID: 21750681
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      
0
 
LVL 8

Author Comment

by:newbie27
ID: 21750693
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      
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 8

Author Comment

by:newbie27
ID: 21750770
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
                              
0
 
LVL 15

Expert Comment

by:dosth
ID: 21750771
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
0
 
LVL 22

Assisted Solution

by:neeraj523
neeraj523 earned 250 total points
ID: 21750791
For each k in parts
xmlAuthorName = "<a href='#'>" & XMLField(x, "fv_ctitle", False) & "</a><br>"
next

should be

For each x in k
xmlAuthorName = "<a href='#'>" & XMLField(x, "fv_ctitle", False) & "</a><br>"
next

0
 
LVL 8

Author Comment

by:newbie27
ID: 21750872
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
0
 
LVL 8

Author Comment

by:newbie27
ID: 21750923
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
                  
0
 
LVL 8

Author Comment

by:newbie27
ID: 21751016
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...

0
 
LVL 8

Author Comment

by:newbie27
ID: 21751385
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

0
 
LVL 8

Author Comment

by:newbie27
ID: 21751734
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

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now