XML Plugins return data

Questions and answers on developing, deploying and using plugins and JavaBeans

XML Plugins return data

Postby Gordon McLean » Thu Sep 24, 2015 4:00 pm

Hi
I am trying to extract the value of the credits node from an XML string as follows

HTTP<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE response PUBLIC
"-//textmarketer.biz//DTD Web Services REST 1.6//EN"
"http://api.textmarketer.co.uk/services/rest/DTD/credits_get.dtd">
<response processed_date="2015-09-24T14:45:41+01:00">
<credits>2390</credits>
</response>

I want to return the credits value and I am getting no response using

var XML2 = plugins.XmlReader.readXmlDocumentFromString('The string here');
application.output(XML2[0].getName()); //returns the word 'response' which is expected
var child = XML2[0].getChildNodes()
application.output(child) //outputs []

I was expecting to get <credits> and wanting to get 2390

Anyone with any XML expertise can you point me in the right direction ?

many thanks

Gordon McLean
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: XML Plugins return data

Postby mboegem » Thu Sep 24, 2015 5:19 pm

Hi Gordon,

Problem is in the iterator
XML2[0] = <!DOCTYPE response PUBLIC
"-//textmarketer.biz//DTD Web Services REST 1.6//EN"
"http://api.textmarketer.co.uk/services/rest/DTD/credits_get.dtd">
Code: Select all
XML2[0].getType() == 'UNKNOWN'


XML2[1] = <response processed_date="2015-09-24T14:45:41+01:00">
<credits>2390</credits>
</response>
Code: Select all
XML2[1].getType() == 'ELEMENT'


So:
Code: Select all
XML2[1].getChildNodes()[0].getTextValue()

Is what you're looking for.
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1749
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: XML Plugins return data

Postby Gordon McLean » Thu Sep 24, 2015 5:30 pm

BRILLIANT - thanks Marc much appreciated

Gordon
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 5 guests

cron