This is my working code<div><div>def getCPU</div><div> cmd="onevm show -x #{VMID}|tr -d '\n'|tr -d ' '" #remove newline and space, otherwise cannot read CDATA</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>vm=`#{cmd}`</div>
<div> doc=REXML::Document.new(vm).root</div><div> $cpu=doc.elements['/VM/TEMPLATE/CPU'].text.strip</div><div>end</div><div><br></div><br><div class="gmail_quote">On Tue, Nov 30, 2010 at 5:35 PM, Shi Jin <span dir="ltr"><<a href="mailto:jinzishuai@gmail.com">jinzishuai@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I got it. Somehow if the output is<div><div><CPU></div><div> <![CDATA[2]]></div><div></CPU></div><div>
in multiple lines, it does not work.</div><div><br></div><div>If it is just one line: </div><div><CPU><![CDATA[2]]></CPU></div>
<div>It works.</div><div><br></div><div>But my opennebula-2.0.01 (git) outputs them in multiple lines. </div><div>I see an older version puts them in a single line. Maybe this is why hector gets his to work.</div><div>So the questions are: </div>
<div>1. can we put them back to a single line?</div><div>2. Shall we still be able to parse XML CDATA on multiple lines?</div><div><br></div>Thanks.</div><div>Shi<div><div></div><div class="h5"><br><div class="gmail_quote">
On Tue, Nov 30, 2010 at 5:30 PM, Shi Jin <span dir="ltr"><<a href="mailto:jinzishuai@gmail.com" target="_blank">jinzishuai@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Really? I am confused.<div>Can you run the following code and see if your output is the same as mine?</div><div><div>[cloudadmin@rhel6-one2 cgroups]$ cat test </div>
<div>#!/usr/bin/ruby</div><div>require 'rexml/document'</div>
<div>vmcdata=<<XML</div><div><CPU></div><div> <![CDATA[2]]></div><div></CPU></div><div>XML</div><div><br></div><div>doc=REXML::Document.new(vmcdata).root</div><div>puts doc</div><div>puts doc.text</div>
<div><br></div><div>vmold=<<XML</div><div><CPU></div><div>2</div><div></CPU></div><div>XML</div><div><br></div><div>docold=REXML::Document.new(vmold).root</div><div>puts docold</div><div>puts docold.text</div>
<div>[cloudadmin@rhel6-one2 cgroups]$ ./test </div><div><CPU></div><div> <![CDATA[2]]></div><div></CPU></div><div><br></div><div> </div><div><CPU></div><div>2</div><div></CPU></div><div>
<br>
</div><div>2</div></div><div><div>[cloudadmin@rhel6-one2 cgroups]$ ruby --version</div><div>ruby 1.8.7 (2010-06-23 patchlevel 299) [x86_64-linux]</div></div><div><br></div><div><br></div><div>Thanks.</div><div><br></div>
<div>
Shi</div><div><div><div></div><div><br><div class="gmail_quote">On Tue, Nov 30, 2010 at 5:18 PM, hector <span dir="ltr"><<a href="mailto:hector@convivencial.org" target="_blank">hector@convivencial.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
CDATA labels are ignored by REXML so you shouldn't worry about them.<br>
It's like they're not there.<br>
<br>
Im testing your example and it simply works. Perhaps you can give some<br>
more input on the problem? As I say, it shoudln't be CDATA related if<br>
working with REXML.<br>
<br>
Héctor<br>
<br>
<br>
El 01/12/10 01:07, Shi Jin escribió:<br>
<div><div></div><div>> Hi there,<br>
><br>
> 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<br>
> <CPU><![CDATA[2]]></CPU><br>
> which used to be just<br>
> <CPU><2></CPU><br>
><br>
> 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<br>
> def getCPU<br>
> vm=`onevm show #{VMID} -x`<br>
> doc=REXML::Document.new(vm).root<br>
> $cpu=doc.elements['/VM/TEMPLATE/CPU'].text.strip<br>
> end<br>
><br>
> Thanks a lot.<br>
><br>
> Shi<br>
><br>
> --<br>
> Shi Jin, PhD<br>
><br>
><br>
><br>
> _______________________________________________<br>
> Users mailing list<br>
> <a href="mailto:Users@lists.opennebula.org" target="_blank">Users@lists.opennebula.org</a><br>
> <a href="http://lists.opennebula.org/listinfo.cgi/users-opennebula.org" target="_blank">http://lists.opennebula.org/listinfo.cgi/users-opennebula.org</a><br>
><br>
<br>
<br>
</div></div>--<br>
<font color="#888888">Hector<br>
</font><div><div></div><div>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.opennebula.org" target="_blank">Users@lists.opennebula.org</a><br>
<a href="http://lists.opennebula.org/listinfo.cgi/users-opennebula.org" target="_blank">http://lists.opennebula.org/listinfo.cgi/users-opennebula.org</a><br>
</div></div></blockquote></div><br><br clear="all"><br></div></div>-- <br>Shi Jin, Ph.D.<br><br>
</div>
</blockquote></div><br><br clear="all"><br></div></div>-- <br>Shi Jin, Ph.D.<br><br>
</div>
</blockquote></div><br><br clear="all"><br>-- <br>Shi Jin, Ph.D.<br><br>
</div>