Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > REXML: Raw tags in element text?

Reply
Thread Tools

REXML: Raw tags in element text?

 
 
Jari Williamsson
Guest
Posts: n/a
 
      11-23-2007
In REXML, is it possible to add raw tags to element text, without having
to add elements for those tags?
(I would like to add a few HTML tags like <b></b> to strings, before I
know what element nodes they will appear at.)


Best regards,

Jari Williamsson

 
Reply With Quote
 
 
 
 
Phrogz
Guest
Posts: n/a
 
      11-24-2007
On Nov 23, 2:26 pm, Jari Williamsson
<(E-Mail Removed)> wrote:
> In REXML, is it possible to add raw tags to element text, without having
> to add elements for those tags?
> (I would like to add a few HTML tags like <b></b> to strings, before I
> know what element nodes they will appear at.)


Are you wanting to ad XML elements as children of another without
using the DOM to create them (like setting .innerHTML in a web
browser, causing it to parse your string and create elements as
necessary),

or are you wanting to set the contents of a text node to have
characters that look like XML tags, but have it automatically escape
them for you?
 
Reply With Quote
 
 
 
 
Jari Williamsson
Guest
Posts: n/a
 
      11-24-2007
Phrogz wrote:
> On Nov 23, 2:26 pm, Jari Williamsson
> <(E-Mail Removed)> wrote:
>> In REXML, is it possible to add raw tags to element text, without having
>> to add elements for those tags?
>> (I would like to add a few HTML tags like <b></b> to strings, before I
>> know what element nodes they will appear at.)

>
> Are you wanting to ad XML elements as children of another without
> using the DOM to create them (like setting .innerHTML in a web
> browser, causing it to parse your string and create elements as
> necessary),


Yes, this is what I want.


Best regards,

Jari Williamsson

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      11-24-2007
2007/11/24, Jari Williamsson <(E-Mail Removed)>:
> Phrogz wrote:
> > On Nov 23, 2:26 pm, Jari Williamsson
> > <(E-Mail Removed)> wrote:
> >> In REXML, is it possible to add raw tags to element text, without having
> >> to add elements for those tags?
> >> (I would like to add a few HTML tags like <b></b> to strings, before I
> >> know what element nodes they will appear at.)

> >
> > Are you wanting to ad XML elements as children of another without
> > using the DOM to create them (like setting .innerHTML in a web
> > browser, causing it to parse your string and create elements as
> > necessary),

>
> Yes, this is what I want.


I believe you can do it (i.e. add raw tags to text) BUT they will not
show up as tags when output. Which is completely logical once you
think about it. If you work with a DOM you have to add nodes as
nodes. Maybe you can just create a small sub tree with a <b> node and
your text as nested text and later put that <b> node into the tree.

Kind regards

robert

--
use.inject do |as, often| as.you_can - without end

 
Reply With Quote
 
Jari Williamsson
Guest
Posts: n/a
 
      11-24-2007
Robert Klemme wrote:
> 2007/11/24, Jari Williamsson <(E-Mail Removed)>:
>> Phrogz wrote:
>>> On Nov 23, 2:26 pm, Jari Williamsson
>>> <(E-Mail Removed)> wrote:
>>>> In REXML, is it possible to add raw tags to element text, without having
>>>> to add elements for those tags?
>>>> (I would like to add a few HTML tags like <b></b> to strings, before I
>>>> know what element nodes they will appear at.)
>>> Are you wanting to ad XML elements as children of another without
>>> using the DOM to create them (like setting .innerHTML in a web
>>> browser, causing it to parse your string and create elements as
>>> necessary),

>> Yes, this is what I want.

>
> I believe you can do it (i.e. add raw tags to text) BUT they will not
> show up as tags when output. Which is completely logical once you
> think about it. If you work with a DOM you have to add nodes as
> nodes. Maybe you can just create a small sub tree with a <b> node and
> your text as nested text and later put that <b> node into the tree.


Since nothing seems to exist I wrote my own 2-line method: It adds a raw
string, parses it and passes all nodes to the parent element. Here's the
code if anyone else would need it:

---
class REXML::Element
def add_raw_text(raw_text)
doc = REXML:ocument.new("<fake>"+raw_text+"</fake>")
doc.root.children.each { |e| self << e }
end
end
---

Example:
myelement.add_raw_text("here's a <b>bold</b> test")


Best regards,

Jari Williamsson

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer Rob Nicholson ASP .Net 3 05-28-2005 03:11 PM
JSP newbie - use include, custom tags, standard tags - or what? Mike Java 3 01-09-2004 09:30 AM
RegEx to find CFML tags nested in HTML tags Dean H. Saxe Perl 0 01-03-2004 06:11 PM
Custom Tags within Custom Tags. Ranganath Java 2 10-21-2003 06:14 AM



Advertisments