[one-users] ONE-2.0 CDATA in XML output
hector
hector at convivencial.org
Wed Dec 1 08:35:51 PST 2010
Hi,
> I got it. Somehow if the output is
> in multiple lines, it does not work.
Yeah, same here :| ...
OpenNebula can produce the XML output both using the Nokogiri gem or
REXML if Nokogiri is not found. I'm using Nokogiri with the last git
version and all CDATA content I can see is on the same line as the
enclosing labels.
Perhaps it is the case that you are not using nokogiri? If so, you can
consider trying again after installing it.
Hector
El 01/12/10 06:25, Shi Jin escribió:
> This is my working code
> def getCPU
> cmd="onevm show -x #{VMID}|tr -d '\n'|tr -d ' '"
> #remove newline and space, otherwise cannot read CDATA
> vm=`#{cmd}`
> doc=REXML::Document.new(vm).root
> $cpu=doc.elements['/VM/TEMPLATE/CPU'].text.strip
> end
>
>
> On Tue, Nov 30, 2010 at 5:35 PM, Shi Jin <jinzishuai at gmail.com
> <mailto:jinzishuai at gmail.com>> wrote:
>
> I got it. Somehow if the output is
> <CPU>
> <![CDATA[2]]>
> </CPU>
> in multiple lines, it does not work.
>
> If it is just one line:
> <CPU><![CDATA[2]]></CPU>
> It works.
>
> But my opennebula-2.0.01 (git) outputs them in multiple lines.
> I see an older version puts them in a single line. Maybe this is why
> hector gets his to work.
> So the questions are:
> 1. can we put them back to a single line?
> 2. Shall we still be able to parse XML CDATA on multiple lines?
>
> Thanks.
> Shi
>
> On Tue, Nov 30, 2010 at 5:30 PM, Shi Jin <jinzishuai at gmail.com
> <mailto:jinzishuai at gmail.com>> wrote:
>
> Really? I am confused.
> Can you run the following code and see if your output is the
> same as mine?
> [cloudadmin at rhel6-one2 cgroups]$ cat test
> #!/usr/bin/ruby
> require 'rexml/document'
> vmcdata=<<XML
> <CPU>
> <![CDATA[2]]>
> </CPU>
> XML
>
> doc=REXML::Document.new(vmcdata).root
> puts doc
> puts doc.text
>
> vmold=<<XML
> <CPU>
> 2
> </CPU>
> XML
>
> docold=REXML::Document.new(vmold).root
> puts docold
> puts docold.text
> [cloudadmin at rhel6-one2 cgroups]$ ./test
> <CPU>
> <![CDATA[2]]>
> </CPU>
>
>
> <CPU>
> 2
> </CPU>
>
> 2
> [cloudadmin at rhel6-one2 cgroups]$ ruby --version
> ruby 1.8.7 (2010-06-23 patchlevel 299) [x86_64-linux]
>
>
> Thanks.
>
> Shi
>
> On Tue, Nov 30, 2010 at 5:18 PM, hector <hector at convivencial.org
> <mailto:hector at convivencial.org>> wrote:
>
> CDATA labels are ignored by REXML so you shouldn't worry
> about them.
> It's like they're not there.
>
> Im testing your example and it simply works. Perhaps you can
> give some
> more input on the problem? As I say, it shoudln't be CDATA
> related if
> working with REXML.
>
> Héctor
>
>
> El 01/12/10 01:07, Shi Jin escribió:
> > Hi there,
> >
> > I used to have some ruby script to parse the output of
> "onevm show <vmid> -x". After switching from 1.4 to 2.0,
> they no longer work. I think the problem is that now the
> output of the XML has lots of CDATA in it. For example
> > <CPU><![CDATA[2]]></CPU>
> > which used to be just
> > <CPU><2></CPU>
> >
> > I am not a Ruby expert. Is there any easy way to parse the
> XML in Ruby to get the CDATA data? My code looks like
> > def getCPU
> > vm=`onevm show #{VMID} -x`
> > doc=REXML::Document.new(vm).root
> >
> $cpu=doc.elements['/VM/TEMPLATE/CPU'].text.strip
> > end
> >
> > Thanks a lot.
> >
> > Shi
> >
> > --
> > Shi Jin, PhD
> >
> >
> >
> > _______________________________________________
> > Users mailing list
> > Users at lists.opennebula.org <mailto:Users at lists.opennebula.org>
> > http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
> >
>
>
> --
> Hector
> _______________________________________________
> Users mailing list
> Users at lists.opennebula.org <mailto:Users at lists.opennebula.org>
> http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
>
>
>
>
> --
> Shi Jin, Ph.D.
>
>
>
>
> --
> Shi Jin, Ph.D.
>
>
>
>
> --
> Shi Jin, Ph.D.
>
--
Hector
More information about the Users
mailing list