title image


Smiley Re: XML-Datei aus MySQL-DB erzeugen.
So, hier:





/**

* this implements a method to check a StringBuffer

* for XMLChars and replaces them with Substitute Strings.

* @author Nic2

*/

public abstract class XMLFilter {



/** Creates a new instance of XMLFilter */

public XMLFilter() {

}



/**

*checks if special characters like '' or '&' have been typed in to database.

*Those would force the methods parsing XML to throw an Exception.

*Those 'dirty' chars are checked and replaced with the XML compatible chars when found.

*Its important first to check for ampersands ('&') and then for other chars because the

*ampersand is always part of the substitution value.

*

*@param StringBuffer dirtySB - StringBuffer to be checked and maybe modified

*/

public static void filterXMLChars(StringBuffer dirtySB) throws Exception {

//dirty chars

ArrayList dirty = new ArrayList();

dirty.add("&");

dirty.add(">");

dirty.add("<");



//clean Strings

ArrayList clean = new ArrayList();

clean.add("&");

clean.add(">");

clean.add("<");



String dirtySTR;



for (int i = 0; i < dirty.size(); i++) {

int index = 0;

//solange noch ein 'dirty' Zeichen gefunden wird...

while (index != -1) {

dirtySTR = new String(dirtySB);

//Suche ab der letzen Fundstelle

index = dirtySTR.indexOf(dirty.get(i).toString(), index);

if (index != -1) {

//System.out.println("SQL2XML replace dirtySB: " + dirtySB);

dirtySB.replace(index, index+1, clean.get(i).toString());

//System.out.println("SQL2XML replaced dirtySB: " + dirtySB);

index = index + 1;

}

}

}

}

}




---------------------------------------------------------------------------
"The hero, then, is not time, but timelessness."
(Henry Miller)

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: