0

i'd like to know how i can browse this XML file to get some values (like VersionXSD, Support, etx...). Without namespaces i can do it but with namespace i get no result.

<?xml version="1.0" encoding="UTF-8"?>
<ROOT Id="myRefId"
xsi:schemaLocation="urn:ir:si_my_xsd_07.xsd"
xmlns="urn:ir:se_pelmed" xmlns:nmsps="urn:siram:nmsps"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Horodatage>2013-03-05T12:00:00</Horodatage>
<VersionXSD>01.01</VersionXSD>
<BASE>
    <nmsps:Numero>NUM-123-456</nmsps:Numero>
    <nmsps:Type>TATA</nmsps:Type>
    <nmsps:Support>PASTIS</nmsps:Support>
    <nmsps:DateLimite>2013-03-04</nmsps:DateLimite>
    <nmsps:Serial>0</nmsps:Serial>
    <nmsps:BASEA>
        <nmsps:NomFamille>Paul</nmsps:NomFamille>
        <nmsps:Prenom>Hilaire</nmsps:Prenom>
        <nmsps:DateNai>1979-10-11</nmsps:DateNai>
        <nmsps:Sexe>Masculin</nmsps:Sexe>
    </nmsps:BASEA>
    <nmsps:BASEC Id="1">
        <nmsps:Validite>2013-03-04</nmsps:Validite>
        <nmsps:Sub>true</nmsps:Sub>
        <nmsps:Stup>true</nmsps:Stup>
    </nmsps:BASEC>
    <nmsps:BASED Id="1">
        <nmsps:Numero R="DD1">numero1</nmsps:Numero>
        <nmsps:Categorie>Categorie1</nmsps:Categorie>
    </nmsps:BASED>
    <nmsps:BASED Id="2">
        <nmsps:Numero R="DD2">numero2</nmsps:Numero>
        <nmsps:Categorie>Categorie2</nmsps:Categorie>
    </nmsps:BASED>
    <nmsps:BASED Id="3">
        <nmsps:Numero R="DD3">numero3</nmsps:Numero>
        <nmsps:Categorie>Categorie3</nmsps:Categorie>
    </nmsps:BASED>
</BASE>
</ROOT>
VRTHT
  • 73
  • 1
  • 8
  • You must provide a NamespaceContext to the XPath. There's no default impl of that class, you have to instantiate one yourself. see http://stackoverflow.com/questions/8221652/how-to-retrieve-xml-data-using-xpath-which-contains-namespace-in-java/8221812#8221812 – flup Mar 13 '13 at 19:37

1 Answers1

0

You can either bypass the namespace using local-name() i.e. //*[local-name()='Support']

or instantiate one as flup suggested, which is how I would do it, it makes things much easier.

JWiley
  • 3,129
  • 8
  • 41
  • 66