Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] Removing illegal characters from element names

Simon Metson

2004-07-08

Replies:

Hi All,
  I'm new to the list so I appologise if this has already been
answered but after trawling Google for an hour I can't find the info I
need. I'm writing a class that takes the result of any sql statement and
returns a JDOM xml document with elements named after the column name,
something like;
<results>
<processed_sql>SELECT * from test where field1 like '%h%';</processed_sql>
<result_set>
  <row>
   <field1>hello</field1>
   <field2>world</field2>
  </row>
  <row>
   <field1>blah</field1>
   <field2>eggs</field2>
  </row>
</result_set>
</results>

as the sql can be any sql there is a possibility of illegal characters
eg doing;

  SELECT field1, field2, field1 + field2 from test where field1 like
'%h%';

will throw;

org.jdom.IllegalNameException: The name "field1_+_field2" is not legal
for JDOM/XML elements: XML names cannot contain the character "+".

(as you can see I already replace the space with underscore). Is there a
quick way of replacing all illegal characters in my element names? My
current plan is to take a look at the JDOM source to work out a regexp
to fix this, any better suggestions?
Cheers
Simon

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.