Hallo zusammen!
Ich arbeite momentan mit XML und SAX. Mein Auftrag lautet, mit der Hilfe von SAX einige Elemente auszulesen und in der Konsole auszugeben. hier ein Ausschnitt aus dem XML- File:
[XML=221]
<daxroductPropertyDefinition name="fqCode" saleRelevance="false" use="singleOptional">
<dax:label lang="ALL">1. FQ-Code</dax:label>
</daxroductPropertyDefinition>
<daxroductPropertyDefinition name="destination" saleRelevance="true" use="singleRequired">
<dax:label lang="GER">Bestimmung</dax:label>
<dax:label lang="FRA">destination</dax:label>
<dax:label lang="ITA">destinazione</dax:label>
</daxroductPropertyDefinition>
<daxroductPropertyDefinition name="origin" saleRelevance="true" use="singleRequired">
<dax:label lang="GER">Abgang</dax:label>
<dax:label lang="FRA">départ</dax:label>
<dax:label lang="ITA">partenza</dax:label>
</daxroductPropertyDefinition>
[/XML]
Nun möchte ich gerne wissen, wie ich das Attribut "name" ausgeben lassen kann. Und zwar nur dann, wenn der Wert des Attributes "destination" und/oder "origin" ist.
Ich hoffe, ihr könnt mir helfen. Hier ist noch die startElement-Methode der Java Klasse von mir.
[JAVA=35]
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
if (qName.equals("dax:articleId")) {
// System.out.print("<" + atts);
for (int index = 0; index < atts.getLength(); index++) {
System.out.println(atts.getLocalName(index) + " " + atts.getValue(index));
}
if (qName.equals("daxroductPropertyDefinition")) {
if (atts.getValue(0) == "origin") {
System.out.println(atts.getLocalName(0) + " " + atts.getValue(0));
}
}
}
}[/code]
Irgendwo mache ich einen groben Denkfehler. Ich habe im Moment ein Brett vor dem Kopf. Aber ich bin auch sonst nicht so der JAVA-Crack :noe:
Gruss
Ahunzs
Ich arbeite momentan mit XML und SAX. Mein Auftrag lautet, mit der Hilfe von SAX einige Elemente auszulesen und in der Konsole auszugeben. hier ein Ausschnitt aus dem XML- File:
[XML=221]
<daxroductPropertyDefinition name="fqCode" saleRelevance="false" use="singleOptional">
<dax:label lang="ALL">1. FQ-Code</dax:label>
</daxroductPropertyDefinition>
<daxroductPropertyDefinition name="destination" saleRelevance="true" use="singleRequired">
<dax:label lang="GER">Bestimmung</dax:label>
<dax:label lang="FRA">destination</dax:label>
<dax:label lang="ITA">destinazione</dax:label>
</daxroductPropertyDefinition>
<daxroductPropertyDefinition name="origin" saleRelevance="true" use="singleRequired">
<dax:label lang="GER">Abgang</dax:label>
<dax:label lang="FRA">départ</dax:label>
<dax:label lang="ITA">partenza</dax:label>
</daxroductPropertyDefinition>
[/XML]
Nun möchte ich gerne wissen, wie ich das Attribut "name" ausgeben lassen kann. Und zwar nur dann, wenn der Wert des Attributes "destination" und/oder "origin" ist.
Ich hoffe, ihr könnt mir helfen. Hier ist noch die startElement-Methode der Java Klasse von mir.
[JAVA=35]
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
if (qName.equals("dax:articleId")) {
// System.out.print("<" + atts);
for (int index = 0; index < atts.getLength(); index++) {
System.out.println(atts.getLocalName(index) + " " + atts.getValue(index));
}
if (qName.equals("daxroductPropertyDefinition")) {
if (atts.getValue(0) == "origin") {
System.out.println(atts.getLocalName(0) + " " + atts.getValue(0));
}
}
}
}[/code]
Irgendwo mache ich einen groben Denkfehler. Ich habe im Moment ein Brett vor dem Kopf. Aber ich bin auch sonst nicht so der JAVA-Crack :noe:
Gruss
Ahunzs
Zuletzt bearbeitet von einem Moderator: