[jdom-interest] adding attributes from a string
    Per Norrman 
    per.norrman at austers.se
       
    Sat Sep  1 03:09:59 PDT 2007
    
    
  
Hi,
Construct valid xml from the <source> element text. Ssomething like this:
    SAXBuilder builder = new SAXBuilder();
    String source = "<source>firstname='john' lastname='doe' age='42'</source>";
    Document doc = builder.build(new StringReader(source));
    String constructed = "<result " + doc.getRootElement().getText() + "/>";
    Document result = builder.build(new StringReader(constructed));
    new XMLOutputter().output(result, System.out);
/per
Stefan Shoeman skrev:
> Hey,
> 
> how is it possible to add attributes from a string (an example follows
> below) to an element?
> 
> Because I have some attributes as text between two tags:
> <source>firstname="john" lastname="doe" age="42"</source>
> 
> => string: [firstname="john" lastname="doe" age="42"]
> 
> ...which should become:
> <result firstname="john" lastname="doe" age="42"></result>
> 
> Sadly the source xml is given as it is and I don't have any chance to
> change it for better fitting into jdom. Any hints would be
> appreciated.
> 
> Thanks for reading...
> 
> Regards,
> 
> Stefan
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> 
> 
    
    
More information about the jdom-interest
mailing list