Merci pour ta réponse. text() c'est pour quoi en fait? Pour dire que le nœud est de type text? Mon problème venait du getNodeValue() :)
A+
-----Message d'origine-----
De : xml-tech-bounce@xmlfr.org [mailto:xml-tech-bounce@xmlfr.org] De la part de Jean-Marc Desprez
Envoyé : vendredi 19 mai 2006 11:18
À : xml-tech@xmlfr.org
Objet : [xml-tech] Re: utiliser Xercès pour parser un InputStream ou String?
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, sjarlier@stradefi.com <sjarlier@stradefi.com> 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
>
--
Devenez redacteur <XML>fr et contribuez au developpement du
xml francophone (http://xmlfr.org/infos/redacteurs/) !
Liste de diffusion "xml-tech@xmlfr.org" (http://xmlfr.org).
Cette liste est a votre disposition pour discuter en francais de
tout sujet technique lie a XML.
Pour resilier votre abonnement, envoyez un message contenant
la commande "unsubscribe" a xml-tech-request@xmlfr.org
(mailto:xml-tech-request@xmlfr.org?Subject=unsubscribe)
__________ NOD32 1.1547 (20060518) Information __________
This message was checked by NOD32 antivirus system.
http://www.eset.com
--
Devenez redacteur <XML>fr et contribuez au developpement du
xml francophone (http://xmlfr.org/infos/redacteurs/) !
Liste de diffusion "xml-tech@xmlfr.org" (http://xmlfr.org).
Cette liste est a votre disposition pour discuter en francais de
tout sujet technique lie a XML.
Pour resilier votre abonnement, envoyez un message contenant
la commande "unsubscribe" a xml-tech-request@xmlfr.org
(mailto:xml-tech-request@xmlfr.org?Subject=unsubscribe)
Received on Fri May 19 11:49:16 2006