Post

0 followers Follow
0
Avatar

How do I create a jDomElement from a XML string?

This is a locked post that has been migrated from our previous forum. Please start a new post if you would like to continue the discussion.

Geneious User:

I'm working on a plugin that will allow the user to update custom notes fields (and does other things with the data at the same time...I know that they can update directly in the notes interface).

I'm having trouble getting the string containing the XML into the jDomElement so that it can be added to the List. The code pasted below should give you an idea of what I'm trying to do.

Thanks for your help.
A.

private void updateDocument(){
String upDateString = "new Provisional";
Element docXML = thisDocument.toXML();
List listFields = ((Element) docXML.getContent().get(2)).getContent();
List listFields2 = ((Element) listFields.get(0)).getContent();
Object newJdomElement = someMethod(upDateString);//what do I do here????
System.out.println(newJdomElement.toString());// [Element: ]
System.out.println(newJdomElement.getClass()); //class org.jdom.Element
listFields2.add(newJdomElement);
try {
thisDocument.fromXML(docXML);
} catch (XMLSerializationException e) {
System.out.println(e.getMessage());
}
thisDocument.saveDocument();

}

Geneious Support:

StringUtilities.parseElement is what you are looking for.

Geneious User:

That worked! Thank you.

For anyone else who needs to do something similar, I'm pasting a functional version of the code in my previous post:

private void updateDocument2() throws JDOMException{
String upDateString = "new Provisional";
Element docXML = thisDocument.toXML();
List listFields = ((Element) docXML.getContent().get(2)).getContent();
List listFields2 = ((Element) listFields.get(0)).getContent();
Element newJdomElement = StringUtilities.parseElement(upDateString);
Element newJdomElementClone = (Element) newJdomElement.clone();
listFields2.add(newJdomElementClone);
try {
thisDocument.fromXML(docXML);
} catch (XMLSerializationException e) {
System.out.println(e.getMessage());
}
thisDocument.saveDocument();

}
Web admin

Post is closed for comments.