ja das werde ich dann jetzt auch mal tun ^^
Das was in der Main steht rufe ich fast 1:1 (außer das println natürlich) in einer jsp auf.
Das XML-File habe ich in der Tabelle so eingefügt:
Der Inhalt hat noch keine tiefere Bedeutung... ist aber auch nicht so wichtig im Moment.
Dankeschön erstmal für deine bisherige Hilfe.^^
MFG
Code:
import java.io.IOException;
import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.*;
import java.io.*;
import org.w3c.dom.*;
import org.apache.xml.serialize.*;
import java.sql.*;
import com.hp.omih.encore.lookups.*;
public class XMLTool
{
static Document doc;
public static String[][][] getXML(InputSource xmlFile)
{
String[][][] matrix = new String[4][4][4];
matrix[1][1][0] = "test";
XMLTool dom1 = new XMLTool(xmlFile);
matrix = dom1.getData(doc.getDocumentElement());
return matrix;
}
public XMLTool(InputSource xmlFile) //parsing xml
{
DOMParser dom = new DOMParser();
try {
dom.setFeature("http://xml.org/sax/features/validation", true);
dom.setFeature("http://apache.org/xml/features/validation/schema",true);
dom.parse(xmlFile);
doc = dom.getDocument();
} catch (SAXException se) {
System.out.println("Fehler beim Parsen: " + se.getMessage());
} catch (IOException e) {
System.out.println("E/A-Fehler: " + e.getMessage());
}
}
public String[][][] getData(Node node) //save id.xml in String[][][]
{
String[][][] matrix = new String[4][4][4];
matrix[1][1][1] = "nuuul";
int ii=0;
NodeList child1 = doc.getElementsByTagName("extensionrow");
for (int i = 0; i < child1.getLength(); i++)
{
NamedNodeMap attribsChild1 = child1.item(i).getAttributes();
matrix[ii][0][0] = attribsChild1.item(0).getNodeName()+" = "+attribsChild1.item(0).getNodeValue();
if (child1.item(i).hasChildNodes())
{
int kk=1;
NodeList child2 = child1.item(i).getChildNodes();
for (int k = 1; k < child2.getLength(); k+=2)
{
NamedNodeMap attribsChild2 = child2.item(k).getAttributes();
//just a previous test///////////
if(attribsChild2.item(0).getNodeValue().equals("emil"))
{
try{
attribsChild2.item(0).setNodeValue("--Franz--");
Element root = doc.getDocumentElement();
FileWriter writer = new FileWriter("id.xml");
XMLSerializer serializer = new XMLSerializer(writer, null);
serializer.serialize(root);
writer.close();
}catch(Exception e){}
}
/////////////////////////
matrix[ii][kk][0] = ""+attribsChild2.item(0).getNodeName().toString()+" = "+attribsChild2.item(0).getNodeValue().toString();
kk++;
}
}
ii++;
}
return matrix;
}
public static void main(String[] args)
{
String[][][] matrix = new String[4][4][4];
matrix[1][1][0] = "test";
ResultSet rs = null;
InputStream xmlStream = null;
String sql="select appro_matrix from app_layer_type where app_layer_type_id='45'"; //only one xml file is selected
try{
Statement stmnt = LookupDB.getStatement("uam"); // uam = DBPool (connect)
rs = stmnt.executeQuery(sql);
}catch (Exception e){System.out.println("No Connection to Pool UAM!");}
try{
while(rs.next())
{ xmlStream = rs.getClob(1).getAsciiStream(); }
}catch (Exception e){System.out.println("Not able to getClob(1).getAsciiStream();");}
InputSource xmlFiles = new InputSource(xmlStream);
// try{
matrix = XMLTool.getXML(xmlFiles);
// }catch(Exception e){test2 = "null = matrix = XMLTool.getXML(xmlFiles)";}
for(int iii=0;iii<4;iii++)
{
for(int kkk=0;kkk<4;kkk++)
{
// for(int lll=0;lll<1;lll++) //<TODO> deeper child in xml
// {
System.out.println(iii+":"+kkk+":"+matrix[iii][kkk][0]+"<br>");
// }
}
}
}
}
Das was in der Main steht rufe ich fast 1:1 (außer das println natürlich) in einer jsp auf.
Das XML-File habe ich in der Tabelle so eingefügt:
Code:
UPDATE app_layer_type
SET appr_matrix='<?xml version="1.0" encoding="UTF-8"?>
<all-extensions>
<extensionrow mgmt="gustav" support="--Franz--" data-owner="">
<extension>BAS</extension>
<extension>Web</extension>
</extensionrow>
<extensionrow mgmt="klaus" support="--Franz--" data-owner="">
<extension>BAS</extension>
<extension>UX</extension>
</extensionrow>
<extensionrow mgmt="" support="rudolf" data-owner="erwin">
<extension>UX</extension>
</extensionrow>
<extensionrow mgmt="erwin support="" data-owner="gustav">
<extension>ODB</extension>
</extensionrow>
</all-extensions>'
where app_layer_type_id='45'
Dankeschön erstmal für deine bisherige Hilfe.^^
MFG