Java Mailing List Archive

http://www.junlu.com/

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

RE: [jdom-interest] Re: Removing illegal characters from element
 names

New, Cecil (GEAE)

2004-07-09

Replies:

I think you could also wrap the sql statement with a CDATA section tag:
<processed_sql>
 <![CDATA[ *** sql with illegal chars here *** ]]>
</processed_sql>

-----Original Message-----
From: Simon Metson [mailto:simon@(protected)]
Sent: Thursday, July 08, 2004 8:18 PM
To: jdom-interest@(protected)
Subject: [jdom-interest] Re: Removing illegal characters from element
names


Hi again,
  Have answered my own question: Verifier.checkXML with a bit of
regexp'ing;

if (Verifier.checkXMLName(colName)=="XML names cannot be null or empty"){
  colName="col"+cCount;
}
while(Verifier.checkXMLName(colName)!=null){
  String[] splitResult = Verifier.checkXMLName(colName).split("\"");
  System.out.println(splitResult[0]);
  System.out.println("duff character: \"" + splitResult[1] + "\"");
             
  //"XML names cannot contain the character \"" + c + "\"";
  colName = colName.replaceAll("\\" + splitResult[1], "_");
  System.out.println(colName);
}

Cheers
Simon

Simon Metson wrote:

> 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)
t.com
_______________________________________________
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.