Re: utiliser Xercès pour parser un InputStream ou String?
"Jean-Marc Desprez" <[email protected]>
| Newsgroups | gmane.text.xml.french.tech |
|---|---|
| Message-ID | <[email protected]> |
Salut, Comme ça, vite fait je te conseil ça String xpath = "/alf-config/procedure-condition/text()"; parce que "condition" est en fait le noeud texte dans ton xml Je n'ai pas testé, dit moi si ça règle ton problème (je pense que oui) A+ Le 19/05/06, [email protected] <[email protected]> a écrit : > > Merci infiniment. > > J'ai quelques soucis pour récupérer la valeur stockée entre tag. > S'il vous plait pourriez-vous me dire ce que je fais de faux? > > J'ai un XML comme suit (en plus complexe): > > <?xml version="1.0" encoding="UTF-8"?> > <alf-config> > <label>label</label> > <!--comment--> > <procedure-condition>condition</procedure-condition> > </alf-config> > > Ensuite j'appelle mon constructeur avec le contenu de mon XML (un String): > > public EthicFlow_DomXMLParser(String xmlContent) > { > DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); > > try { > > // ** Using factory get an instance of document builder > DocumentBuilder db = dbf.newDocumentBuilder(); > > // ** Reader Writer creation from xmlContent > this.in = new StringReader(xmlContent); > this.out = new StringWriter(); > > // ** Parse using builder to get DOM representation of the > XML > //file > this.dom = db.parse(new InputSource(this.in)); > > }catch(ParserConfigurationException pce) { > pce.printStackTrace(); > }catch(SAXException se) { > se.printStackTrace(); > }catch(IOException ioe) { > ioe.printStackTrace(); > } > } > > Et ensuite je veux récupérer procedure-condition c'est-a-dire "condition" > comme ceci: > > public String domXMLParser_getProcedureCondition() > { > String procedureCondition = null; > try > { > String xpath = "/alf-config/procedure-condition"; > NodeList nl = XPathAPI.selectNodeList(this.dom, xpath); > Element element = (Element)nl.item(0); > procedureCondition = element.getNodeValue(); > > } > catch(TransformerException te){ > > Utils.addErrorMessage(MessageFormat.format(Application.getMessage > (FacesConte > xt.getCurrentInstance(), "TransformerException"), te > .getMessage()), te); > //te.printStackTrace(); > } > > return procedureCondition; > } > > Et ca ne plante pas mais je récupère null au lieu de "condition"... > > Merci d'avance > Sophie >