[MOBY-l] Perl API: conversion of node content to and from XML

Neerincx, Pieter Pieter.Neerincx at wur.nl
Mon Mar 7 11:48:14 UTC 2005


Hi all,

I'm pretty new to BioMOBY and have a question about the Perl API. I have some problems with extracting text data from objects like for example the String object. I have something like this:

<String namespace='my.test.ns' id='0001' articleName='query'>some text &amp; more text</String>

The plain text contains for example "&" which has a special meaning in XML. Therefore I have to encode it using "&amp;". If I use the getNodeContentWithArticle sub from CommonSubs.pm it serializes the data resulting in raw XML. Hence the result contains the "&" still encoded as "&amp;". The same thing happens with encoded quotes. If I would be using the extractRawContent sub that would make sense to me. Off course I can convert the encoded stuff from and to raw XML manually, but wouldn't it be nicer if the API would take care of that? Or am I missing something here and is there a good reason the have for example the getNodeContentWithArticle sub return raw XML?

If I change the code like this:

sub getNodeContentWithArticle {

       ### lot's of other stuff ... ###

					# Using ->toString results in raw XML and will
					# not map encoded chars like '&amp;' back to '&'.
					# Fetching node content using -> data will. 
					#$resp .= $_->toString;
					$resp .= $_->data;

       ### lot's of other stuff ... ###

}

decoding the raw XML is taken care of by the API. Any feedback would be appriciated.

Regards,

Pieter Neerincx




More information about the moby-l mailing list