image: memofield
One of the tables from brian's database showing XML stored in a memo field
R E L A T E D   C O N T E N T
ADVERTISEMENT

Hands on: Memos are made of this

Access may not have an XML data type but that doesn’t mean you can’t use it

Mark Whitehorn, Personal Computer World 24 Sep 2007
ADVERTISEMENT

There has been a huge amount of interest in adding support for extra data types to database engines in recent times.

In past columns I have covered the arrival of the multi-valued data type in Access and in September I briefly mentioned the spatial data types due to arrive with SQL Server 2008. Support for XML as a data type appeared in SQL Server 2005.

Access has no direct support for XML but it’s still possible to make use of XML within an Access database if you so wish. If that sounds weird, remember that XML is simply text and as such is amenable to being stored in text and memo fields, probably mainly the latter because XML is rather a verbose language, so it won’t take much data before you run out of space in a text field. Since XML is just text, you are free to write your own functions that manipulate the stored text as XML.

This is exactly what Brian Jones has done in a database about which he emailed me recently. If you’ve bought the DVD edition of PCW, you’ll find DBCNov07.mdb on the cover disc.
It is also on the web.

There now follows an obligatory warning: I haven’t checked out this code and application in depth. As with all code from a third party, you might want to treat it with some caution initially; perhaps using it on an isolated machine until you are sure it is OK. I don’t want this to sound as if I don’t trust Brian, I do. But we all need to be careful.

Brian was kind enough to provide the database so others can benefit from inspecting his XML handling routines and seeing them in action, and I’ve included it for that reason. As anyone who writes code will know, it’s a lot easier to develop your own code if you have a working example to study and compare, so thanks to Brian for this.

As an example of the sort of function you can write, here is one of Brian’s XML handling functions:

Function ParseXML(strXML As String, strTag As String) As String
Dim str As String
Dim lngPos1 As Long
Dim lngPos2 As Long
Dim lngLenStrXML As Long
Dim TagStart As String
Dim TagEnd As String
lngLenStrXML = Len(strXML)
TagStart = “<” & strTag & “>”
TagEnd = “</” & strTag & “>”
Do
lngPos1 = InStr(lngPos2+ 1, strXML, TagStart) + Len(TagStart)
If lngPos1 = Len(TagStart) Then Exit Do
lngPos2 = InStr(lngPos1, strXML, TagEnd)
If lngPos1 > Len(TagStart) Then str = str & Mid(strXML, lngPos1, lngPos2 - lngPos1) & vbCrLf
Loop Until lngPos1 = Len(TagStart)
If Len(str) Then str = Left(str, Len(str) - 2)
ParseXML = str
End Function

Memo to self…
As mentioned above, the data type that’s most likely to be used by anyone wanting to use XML within Access is the memo. Indeed, Brian has done so in his sample database. It was curious, then, that I received a follow-up email from John Clark about the apparently erratic behaviour of this data type.

In the July Q&A pages, I answered John’s question about concatenating text into an Access memo field and in doing so turned up some oddities in its behaviour, writing: “Unfortunately Access doesn’t display the memo field contents at all elegantly, or even at all. If you click around the table the text will sometimes appear. A bug rather than a feature, I fear.”

John undertook some further investigation and these are his findings: “The workable limit on the memo field seems to be far less that the supposed 65,000 characters, which is typically about 11,700 words or 63,000 characters with spaces.

Trying to paste more than about 7,000 words failed with a message: ‘The text is too long to be edited’.


All Software Applications
Tags: Databases

Like this story? Spread the news by clicking below:

Post this to Delicious del.icio.us    Post this to Digg Digg this    Post this to reddit reddit!

Permalink for this story
R E A D E R   C O M M E N T S
M A R K E T P L A C E
Get your free demo of Numara Track-It! 8 - the leading help desk solution for IT related issues.
Make presentations, review documents & share your entire desktop. 30-day free trial! (cc required).
Discover how remote support can fuel your IT business in ways you've never thought of before.
Apply ITIL best practices at your service desk while eliminating integration cost. Learn more here.
WAN based, automated, daily vulnerability assessments. Click here to try and request our whitepapers.
Have your product or service listed here >   
Sponsored links
F E A T U R E D   J O B S
Reading, Berkshire, United Kingdom | EDS
Position # 397874 IP Network Administrator Location - Reading Job Description: There is a requirement for an IP network administrator to join the Infrastructure Services operational support team to manage the movement of network resources, ... more >
London, United Kingdom | The Moving Picture Company
Web Developer - London   MPC's continued success is dependent on a continued investment in technology so that its clients continue to enjoy the highest possible quality of work and service. Key to MPC's offering is ... more >
London, United Kingdom | City of London
ICT Project Officer - Guildhall, London EC2 18-month fixed-term contract Bring your project management expertise to one of the country's most prestigious institutions. The City of London is the local authority for the Square Mile, ... more >
Reading, Berkshire, United Kingdom | EDS
Position - EA Integrator Location - Reading Job Description: A skilled System Integrator to integrate application Test Harnesses to support business requirements. The Candidate will possess specific experience of enterprise systems, component validation and integrating ... more >
More job opportunities