[jdom-interest] Removing illegal characters from element names

Simon Metson simon at senserecords.com
Thu Jul 8 16:10:28 PDT 2004

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;
  <processed_sql>SELECT * from test where field1 like '%h%';</processed_sql>

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 

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?

More information about the jdom-interest mailing list