Google Answers Logo
View Question
 
Q: XML ( Answered,   0 Comments )
Question  
Subject: XML
Category: Computers > Algorithms
Asked by: sandrat-ga
List Price: $2.00
Posted: 21 Jan 2004 10:04 PST
Expires: 20 Feb 2004 10:04 PST
Question ID: 298773
Can I extract data from an XML element (or field), such as a substring
of characters from the data field?  Such as a MID$ function in Basic? 
Can I use XML to do it, or must I drop into a programming language?

Request for Question Clarification by mathtalk-ga on 21 Jan 2004 10:09 PST
Hi, sandrat-ga:

Which XML implementation are you using?  Are you, for example, working
with Microsoft XML DOM, or with another XML parser?

There are XML-based substring functions, but the details will vary
slightly with the implementation.  It is also possible in many
environments to "drop out" to a scripting language to perform light
tasks such as this.

regards, mathtalk-ga

Clarification of Question by sandrat-ga on 21 Jan 2004 12:11 PST
We are attempting to implement a "real-time" exchange of data between
our new Webhire services and our current Cyborg payroll/HR system.  We
have purchased xmlspy from Altova, along with mapforce 2004.  I am
unskilled with XML and have been asked this question by the folks who
set up the Webhire data fields (or elements, or entities, or whatever
the heck they are called; data fields to me) in our organization. 
They have defined a datum which contains department number
concatenated with a hyphen, concatenated with a dept description.  All
they want is the 4-digit department number, since other tables will
tie the description with the number, e.g. "8250 - EVS and Linens" on
the payroll side.  Personally, their data definition was pretty
crappy, but we programmers have to live with it.  That's all I know. 
Thanks for your help.
Answer  
Subject: Re: XML
Answered By: mathtalk-ga on 21 Jan 2004 13:54 PST
 
Hi, sandrat:

The "generic" answer is that XSLT defines a substring function.  It's
not obvious from visiting Webhire's homepages what XML engine they are
relying upon, but presumably you are speaking for folks who are trying
to extract data from the Cyborg side and format it to suit the Webhire
requirements.  I'll try to tackle your question from that angle.

XSLT is an XML-based standard for defining transformations of XML, in
particular from XML to XML (although it also can be used for XML to
text or XML to HTML).  I have written a number of these transforms,
and most XML parsers now make it relatively easy to apply an XSLT (XSL
transformation) document to an XML input to produce the corresponding
output document.

The generic functionality is described here, in the W3C
recommendations for XPATH and XSLT:

[W3C: XPATH String Functions]
http://www.w3.org/TR/xpath#section-String-Functions

Given the specifics of your question, to extract the four digit
department number which precedes a hyphen (and surrounding spaces,
judging by your example), you might want to use the basic
substring(String,1,4) approach, or:

substring-before(String," -")

if there is doubt about the number of digits present.

The fact that you purchased Altova's XMLSpy (which I also own)
suggests that you may be working at the data massaging from a Windows
platform.  One of the options with XMLSpy is to use the MSXML parser,
in which case you may be interested in the equivalent
Microsoft-specific documentation:

[MSXML String Functions]
http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xpath_functions_91f7.asp

[MSXML substring]
http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xpath_functions_5kq6.asp

[MSXML substring-before]
http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xpath_functions_010u.asp

XMLSpy also permits you to directly apply an XSLT "transform" to an
XML document, for testing purposes as I see it, although it may suit
your environment to treat this as a production path.  Their tutorial
describes the steps to perform this with the GUI interface in the
Chapter called XSL Transformation (although the example is XML to
HTML, the illustration should help):

[XMLSpy 2004 Tutorial (PDF)]
http://www.altova.com/documents/xmlspy2004proTutorial.pdf

regards, mathtalk-ga


Search Strategy

Keywords: W3C substring XSLT
://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=W3C+substring+XSLT&btnG=Google+Search

Keywords: MSXML substring XPath
://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=MSXML+substring+XPath&btnG=Google+Search

Keywords: XMLSpy apply transform site:altova.com
://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=XMLSpy+apply+transform+site%3Aaltova.com&btnG=Google+Search

Clarification of Answer by mathtalk-ga on 21 Jan 2004 14:24 PST
One more link.  I like the way this site pulls together a bunch of
outbound links to document topics, such as here for the substring
function:

[TopXML substring function]
http://www.vbxml.com/xsl/funcsubstring.asp

The site seems to have a lot of useful information for those getting
started with XML and programming tasks in particular.

-- mathtalk-ga
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy