1 Reply Latest reply: Jan 28, 2009 3:47 AM by 807588 RSS

    Can I use XPath paths and JDOM setAttribute method to set an Attribute?

    807588
      I was wondering if its possible to setAttributes of some Nodes using XPath. Is it possible or if not is there any workaround?
        • 1. Re: Can I use XPath paths and JDOM setAttribute method to set an Attribute?
          807588
          No, I don't think so.

          Please refer,

          http://www.jdom.org/pipermail/jdom-interest/2005-July/014937.html

          Alternatively you can use something like,
          XPath rootPath = XPath.newInstance("/Persons/Person");
          Element rootElement = (Element)rootPath.selectSingleNode(originalDoc);
                      
          *rootElement.setAttribute("id", "1");*
                     
          XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
          outputter.output(originalDoc, System.out);
          Please post if you find something!

          Edited by: Nirav.Naik on Jan 28, 2009 1:45 AM