rexml

Add XML namespace to existing document in ruby

I need to add an element to an existing XML document which uses a namespace that doesn't exist in the original. How do I do this? Ideally I would like to use REXML for portability, but any common XML library would be okay. An ideal solution would be smart about namespace collisions. I have an xml document which looks like this: <xrds:...

REXML Formatting issues

Hi, I am using REXML to edit an xml file but have ran into difficulties with formatting. My original code looked like this: file = File.new( destination) doc = REXML::Document.new file doc.elements.each("configuration/continuity2") do |element| element.attributes["islive"] = "true" element.at...

Parsing an xml doc with <% %> tags in ruby

I'm looking for a way to parse an xml/html document in ruby, which contains ERB style tags <% %> with ruby code inside. REXML, the built in XML parser won't allow me to do this. I'm aware that I might be able to with a third party library like hpricot, but I'd like to avoid any external dependencies. Is there a way I could get REXML t...

Where does Rails use REXML lib and how to require that part?

I have a gem that uses some of the Rails libs, including action_view and active_controller. Though I require those libs, all tests fail when trying to call some has_text? method, which (as I found out) is part of'rexml/element' lib. Here's what I get: undefined method `has_text?' for "<b>Hello,<i>world</b></i>":String Requiring 'rexml...

How do I control REXML formatting on added elements?

I am a adding a couple of simple elements to a bunch of XML files (plists). The existing XML element I am working on looks like this: <dict> <key>background</key> <string>#FFFFFF</string> <key>caret</key> <string>#000000</string> <key>foreground</key> <string>#000000</string> <key>invisibles</key> <string>#BFBFBF</string...

Iterative Parsing XML

Just getting started with Ruby and have a newbie question re parsing XML. I'm trying REXML (yes, I know hpricot and others exist, but I am starting with REXML to learn.) The problem is how to iteratively proceed through a XML doc like this: <?xml version="1.0" ?> <bars> <bar> <id>29</id> <foo>Something</foo> </bar> ...

Ruby REXML throws ParseException, but PHP xml parser works

I'm trying to call a web service from a PHP page via a Ruby script. The PHP script returns a string and itself calls another web service; I've tested the PHP script alone and it returns a single string. I'm trying to call this method via RPC using the following code: require 'soap/rpc/driver' driver = SOAP::RPC:Driver.new('http://mysi...

Ruby Unit Test : Is this a Valid (well-formed) XML Doc ?

I'm creating an XML document: I want to unit test at least to make sure it's well-formed. So far, I have only been able to approximate this , by using the 'hasElements' in the REXML library. Is there a better way ? Preferably using built-in libraries (I mean libraries that ship with the standard Ruby 1.8.x distro). require "test/unit"...

Deleting all child nodes and text of an element

With reXml using Ruby, I have a particular element and I want to completely clear out all its child nodes and text. I just cannot work out how to do this. Given this : <ug> <oog> Delete<delete/>all<delete/>this </oog> </ug> I want to delete all the children of oog, to end up with this : <ug> <oog> </oog> </ug> I can g...

How do I properly insert an XML document into another using rexml?

I have managed to figure out the primary part of my question, "how do I insert one XML document into another?" The result I get will work but the printed XML is missing a linefeed. s = <<EOF <application> <email> <host>mail.test.com</host> <port>25</port> </email> </application> EOF p = <<EOF <auth> <user>godber</user> ...

Injecting an XML fragment into the current document from an external file

I'm currently parsing an XML file using REXML and trying to come up with a way of inserting an XML fragment from an internal file. Currently, I'm using some logic like the following: doc.elements.each('//include') do |element| handleInclude( element ) end def handleInclude( element ) if filename = element.attributes['file'] ...

Rexml - Parsing Data

I have a XML File in the following format: <?xml version='1.0' encoding='UTF-8'?> <entry xmlns='http://www.w3.org/2005/Atom' xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009' xmlns:app='http://www.w3.org/2007/app' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;DUYGRX85fCp7I2A9WxFWEkQ.&quot;'><id>https...

XSLT transformations in Ruby and JRuby

Simple question: are there any solid XSLT libraries that work in both Ruby and JRuby? REXML works in both, but does not have XSLT support. ruby-xslt doesn't work in JRuby. The latest Nokogiri betas do support JRuby, but the support is still buggy and throws occasional NullPointerExceptions for XML input that works fine in Ruby. (In pa...

Ruby Load multiple xml from a directory in a program to parse them

Hi I want to load a set of xml from a directory and use REXML to parse all the xml in a loop. I cant seem to create File Object after i start reading from a directory i=1 filearray=Array.new documentarray=Array.new directory = 'xml' Dir.foreach(directory).each { |file| next if file == '.' ...

Rendering a string as a color hex value in Ruby on Rails

I have a hex value that I am getting from an XML file and I am trying to use that hex value as the background color for a data table. However, in IE8 it keeps rendering as a string. When I have used <%= h(@dhex1[k]) %> it renders as <%hex>A8960A<%/hex> with hex tags (note % signs are so browser does not think they are tags) in...

removing the xml tags in ruby on rails

I am reading data from an xml doc and placing it on a web page using rails and REMXL. I use @description1=XPath.match( xmldoc, "////description" ) to get the info into an array and just loop through in my view. However when using <%= h(@description1[k]) %> so it looks like <description>fuzzy slippers</description> on the web ...

Renaming XML elements in Ruby?

How does one go about renaming an XML element using REXML or another Ruby library? Thanks for any advice. ...

How does Ruby's REXML or REXML::XPath take an element and access its children nodes?

If the following code in Ruby can print out "browser type" and "count" individually as 2 separate lists, can REXML select each entry and then print out entry['title'].text and entry['dxp:metric'].attr('value') /* not using exact syntax */ on the same line as one list? require 'rexml/document' include REXML xmlfile = File.new("data....

Why is REXML removing elements from the end of the XML object instead of copying?

Hi everyone, We have this method in our Ruby project. It accepts an XML object (which consists of three different "trees") and is supposed to copy X elements from the end. For some reason, what it does is move those elements -- and then the original XML object (which we passed to it) gets cut off. We tried .clone but it doesn't copy th...

Ruby convert single quotes to double quotes in XML

Despite the fact that XML attributs can be defined using single or double quotes, my user is trying to integrate my software with another one that will not accept single quoted attribut values. I user REXML to generate my XMLs. Is there a way to REXML generate double quoted attribute values? If not, is there a way for me to convert it ...