XML
<?xml version="1.0" encoding="UTF-8"?>
<!-- XML Dokumet fuer JUNIT Testobjekte -->
<!-- Test -->
<test>
<HL7_message>
<value>10000001_6.hl7</value>
<t_kis_fall>
<hostcode>10000001</hostcode>
<aufnahmedatum>14.07.2012 17:30</aufnahmedatum>
<entlassdatum>16.07.2012</entlassdatum>
<t_stamm_falltyp>
<hostcode>I</hostcode>
<pk>id</pk>
<fk>falltyp_id</fk>
</t_stamm_falltyp>
<fallart_id>3</fallart_id>
<t_stamm_aufnahmegrund>
<hostcode>E</hostcode>
<pk>id</pk>
<fk>aufnahmegrund_id</fk>
</t_stamm_aufnahmegrund>
</t_kis_fall>
<t_kis_patient>
<hostcode>10001</hostcode>
<vorname>Test</vorname>
<geburtstag>08.06.2008</geburtstag>
<t_stamm_geschlecht>
<hostcode>M</hostcode>
<pk>id</pk>
<fk>geschlecht_id</fk>
</t_stamm_geschlecht>
</t_kis_patient>
<t_kis_bewegung>
<hostcode>100001</hostcode>
<t_stamm_fachabteilung>
<hostcode>CH_UO</hostcode>
<pk>id</pk>
<fk>fachabteilung_id</fk>
</t_stamm_fachabteilung>
<t_stamm_station>
<hostcode>G5</hostcode>
<pk>id</pk>
<fk>station_id</fk>
</t_stamm_station>
<t_stamm_zimmer>
<hostcode>141</hostcode>
<pk>id</pk>
<fk>zimmer_id</fk>
</t_stamm_zimmer>
<prev_id>0</prev_id>
<next_id>0</next_id>
<admit_movement>TRUE</admit_movement>
<falltyp_id>I</falltyp_id>
<von>14.07.2012 17:30</von>
<bis>16.07.2012 11:00</bis>
</t_kis_bewegung>
<t_kis_fallanschrift>
<vorname>Test</vorname>
<name>Eins</name>
<plz>63512</plz>
<ort>Hainburg</ort>
<strasse>Friedrich-Ebertstr.61</strasse>
<telefon>06182-7700169 0176-98273371</telefon>
</t_kis_fallanschrift>
<t_kis_stationsaufenthalt>
<hostcode>100001</hostcode>
<von>14.07.2012 17:30</von>
<bis>16.07.2012 11:00</bis>
<prev_id>0</prev_id>
<next_id>0</next_id>
<t_stamm_falltyp>
<hostcode>I</hostcode>
<pk>id</pk>
<fk>falltyp_id</fk>
</t_stamm_falltyp>
<admit_movement>TRUE</admit_movement>
<t_stamm_station>
<hostcode>222005F</hostcode>
<pk>id</pk>
<fk>station_id</fk>
</t_stamm_station>
<t_stamm_zimmer>
<hostcode>141</hostcode>
<pk>id</pk>
<fk>zimmer_id</fk>
</t_stamm_zimmer>
</t_kis_stationsaufenthalt>
<t_kis_fachabteilungsaufenthalt>
<prev_id>0</prev_id>
<next_id>0</next_id>
<von>14.07.2012 17:30</von>
<bis>16.07.2012 11:00</bis>
<t_stamm_fachabteilung>
<hostcode>CH_UO</hostcode>
<pk>id</pk>
<fk>fachabteilung_id</fk>
</t_stamm_fachabteilung>
</t_kis_fachabteilungsaufenthalt>
</HL7_message>
</test>
<!-- Erste XML AUS DATENBANK Fertig , andere anpassen am Montag -->
package PraktischeStudienphase;
public class XMLAttributes
{
public String value = null;
public String key = null;
public String name = null;
public String pk = null;
public String fk = null;
public XMLAttributes(String key, String value)
{
this.key = key;
this.value = value;
}
public String getValue()
{
return value;
}
public void setValue(String value)
{
this.value = value;
}
public String getKey()
{
return key;
}
public void setKey(String key)
{
this.key = key;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getPk()
{
return pk;
}
public void setPk(String pk)
{
this.pk = pk;
}
public String getFk()
{
return fk;
}
public void setFk(String fk)
{
this.fk = fk;
}
}
package PraktischeStudienphase;
import java.util.List;
public class XMLTable
{
String name = null;
String pk = null;
String fk = null;
List<XMLAttributes> attributes = null;
List<XMLTable> tables = null;
public void AddAddtribute(String key, String value)
{
XMLAttributes attribute = new XMLAttributes(key, value);
attributes.add(attribute);
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getPk()
{
return pk;
}
public void setPk(String pk)
{
this.pk = pk;
}
public String getFk()
{
return fk;
}
public void setFk(String fk)
{
this.fk = fk;
}
public List<XMLAttributes> getAttributes()
{
return attributes;
}
public void setAttributes(List<XMLAttributes> attributes)
{
this.attributes = attributes;
}
public List<XMLTable> getTables()
{
return tables;
}
public void setTables(List<XMLTable> tables)
{
this.tables = tables;
}
}
DOMParser
package PraktischeStudienphase;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
import java.text.AttributedCharacterIterator.Attribute;
public class XMLDOMParser
{
public static void main(String argv[])
{
try
{
File fXmlFile = new File("C:\\Users\\Pascal\\Desktop\\einfallfertig.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("HL7_message");
System.out.println("-----------------------");
NodeList tagliste=document.getElementsByTagName ("Vorname");
for (int temp = 0; temp < nList.getLength(); temp++)
{
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) nNode;
System.out.println(getTagValue("value",eElement));
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private static String getTagValue(String sTag,Element eElement)
{
NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
}
}
Hallo ich moechte mit dem DOMParser ueber die Liste laufen und schauen ob der Tag kinder besitzt oder nicht , falls ja soll er nen neuen Table erstellen. falls nein soll er nen attribut hinzufuegen.
Das problem ist , ich kenne die Tagnamen vorher nicht ,z.b. value.... t_kis_fall
er muss das ganze dynamisch anhand der XML Struktur erkennen. ist dasmoeglich?