ERLEDIGT
NEIN
NEIN
ANTWORTEN
1
1
ZUGRIFFE
586
586
EMPFEHLEN
-
Code :
1 2 3 4 5 6 7 8 9 10 11
<MyDoc> <No> <INT>1</INT> </No> <No> <Boolean>true</Boolean> </No> </MyDoc>
Parser Klasse
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
import java.io.IOException; import javax.xml.namespace.QName; import javax.xml.parsers.*; import javax.xml.xpath.*; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class XMLParser { private String xmlFile; private Document xmlDocument; private XPath xPath; /* * Parser */ public XMLParser(String xmlFile) { this.xmlFile = xmlFile; initObjects(); } private void initObjects() { try { xmlDocument = DocumentBuilderFactory.newInstance() .newDocumentBuilder().parse(xmlFile); xPath = XPathFactory.newInstance().newXPath(); } catch (IOException ex) { ex.printStackTrace(); } catch (SAXException ex) { ex.printStackTrace(); } catch (ParserConfigurationException ex) { ex.printStackTrace(); } } public Object read(String expression, QName returnType) { try { XPathExpression xPathExpression = xPath.compile(expression); return xPathExpression.evaluate(xmlDocument, returnType); } catch (XPathExpressionException ex) { ex.printStackTrace(); return null; } } }
Query Klasse mit der ich nach Parametern suche und Ausgebe
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
import java.net.URL; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.xml.xpath.XPathConstants; public class XMLQuery { XMLParser parser; public XMLQuery() { parser = new XMLParser("src/res/files/roadmap.xml"); } public String getAction(int i){ String expression = "/MyDoc/NO["+i+"]/IN"; String integer = parser.read(expression, XPathConstants.STRING).toString(); return integer ; } public static void main(String[] args) { XMLQuery q = new XMLQuery(); q.getAction(22); q.getPath(2); } }
So bekomme ich ja nur die Strings zurück, kann mir einer ein Tip geben wie ich das
als Integer und Boolischen Wert zurück bekomme.
Das Casten hat nicht funktionieren wollen, wie ich es auch gemacht habe, von String to Integer oder von Typ Object (XPathConstants.NUMBER) bekomme ich nicht zu Integer gecastet.
Danke für eure Hilfe,
gruss benGeändert von benomatic (16.01.09 um 22:16 Uhr)
-
Hat sich erledigt, mit Integer.decode(String s) konnte ich es zu int casten.
Danke trotzdem
Ähnliche Themen
-
Datentypen
Von mdap im Forum VisualStudio & MFCAntworten: 1Letzter Beitrag: 09.07.10, 14:32 -
VBA Datentypen
Von WiZdooM im Forum Visual Basic 6.0Antworten: 2Letzter Beitrag: 18.03.09, 09:30 -
einlesen von Datentypen
Von thehasso im Forum JavaAntworten: 0Letzter Beitrag: 26.02.09, 22:37 -
Datentypen und Formatierung
Von Majak im Forum C/C++Antworten: 2Letzter Beitrag: 23.04.08, 23:42 -
Datentypen in DLLs
Von chriss_2oo4 im Forum C/C++Antworten: 5Letzter Beitrag: 13.12.07, 16:02





Zitieren
Login





