Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: How to Pull xml data out of table field? Post Reply Post New Topic
Author Message
bigbloo
Newbie
Newbie
Avatar

Joined: 09 Mar 2010
Location: Canada
Online Status: Offline
Posts: 19
Quote bigbloo Replybullet Topic: How to Pull xml data out of table field?
     Posted: 11 Mar 2010 at 1:38pm
My sql db has some fields which, instead of single values, have xml records in them with many data elements. 
For Report Designer, how do I get at (what do I call it)one specific element in an xml record?  Confused
 
Thank you !
Bigbloo
--------------------------------------------------
Information is power only when it's shared.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 17 Mar 2010 at 3:28am
since no one has responded...
 
CR can read XML as a datasource, but as an embedded source, I doubt it...it will see it as the string.
 
what do you mean by one data element?  Do you want all occurrances?  Either way the solution is about the same.  You would look for your tag in the string using INSTR(), then you would want to find the location of the closing tag, and finally you would want to extract the value.
 
If you want all the values, just loop and add them to a delimited string...Something like:
 
local numbervar iStart:=0;
local numbervar iEnd;
local numbervar iTag:=len("<xml tag>")
local stringvar sValue:="";
 
iStart := instr(istart+1,{table.field}, "<xml tag>") + iTag;
if iStart > 0 then(
  iEnd:=instart(istart, {table.field}"</xml tag>");
  sValue := sValue + mid({table.field}, iStart, iEnd - iStart - 1);
)
 
sValue
 
This will get the first occurrance of the field.  You can add a loop very easily to the above (look in help for the syntax).
 
Adding a loop will bring a list of values.  If you need to perform any sort of counting or summing, you will need to do that in the formula as.
 
HTH
IP IP Logged
bigbloo
Newbie
Newbie
Avatar

Joined: 09 Mar 2010
Location: Canada
Online Status: Offline
Posts: 19
Quote bigbloo Replybullet Posted: 17 Mar 2010 at 6:11am
Thanks to DBLANK and LOCKWELL for their valuable input.
The solution we went with, was to create a view of the database which had the xml record fields parsed. CR uses a field with the view table.
Bigbloo
--------------------------------------------------
Information is power only when it's shared.
IP IP Logged
chris
Newbie
Newbie


Joined: 02 Apr 2008
Location: United Kingdom
Online Status: Offline
Posts: 35
Quote chris Replybullet Posted: 25 Jun 2013 at 5:16am
Sorry to bump this but I hope someone can help me with a similar request.

I have a table that I'm reporting from in Crystal that contains an audit log of all changes made to our system.

Each row in the table is a record of a change to a form on our system that has been made. Within each row is a memo field that contains the exact details of all the changes made to that form - field name, old value, new value etc. The language used in this memo field appears to be XML.

Can you please explain to me what parsing means in this scenario and how this has helped solve this issue ? Has creating the view given you the ability to report on the individual fields that form part of the XML ?

Regards
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum