Re: adding attributes from a string

Per Norrman <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
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/[email protected]
> 
> 

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.