[jdom-interest] help basic parsing

Laurent Bihanic laurent.bihanic at atosorigin.com
Wed Feb 21 08:36:19 PST 2007


Using XPath, you should be able to do the following (not tested) :

Document doc = new SAXBuilder().build(...);

XPath xpath = 
XPath.newInstance("//ns1:gbean[@name='RMIRegistry']/ns1:attribute[@name='port']");
xpath.addNamespace("ns1", "http://geronimo.apache.org/xml/ns/attributes-1.1");

Element port = (Element) xpath.selectSingleNode(doc);
port.setText("8080");

Laurent

Jack a écrit :
> hello,
> i'm trying to use jdom with the following xml file.
> i had like to change the port number (here 1099).
> how can i retrieve the text value of the attribute port ?
> i have used 3 iteration loop  but i'm sure there's less complicated.
> thanks.
> 
> <attributes xmlns="http://geronimo.apache.org/xml/ns/attributes-1.1">
>   <module name="geronimo/rmi-naming/1.1.1/car">
>      <gbean name="RMIRegistry">
>         <attribute name="port">1099</attribute>
>      </gbean>
>      <gbean name="NamingProperties">
>         <attribute name="namingProviderUrl">rmi://0.0.0.0:1099</attribute>
>      </gbean>
>      <gbean name="DownloadedPluginRepos">
>         <attribute 
> name="repositoryList">http://download.boulder.ibm.com/ibmdl/pub/software/websphere/wasce/plugins-1.1.1/default-repositories.txt</attribute>
>         <attribute name="userRepositories">[]</attribute>
>      </gbean>
>   </module>
> </attributes>


More information about the jdom-interest mailing list