use of org.jdom.Comment in project vcell by virtualcell.
the class XmlHelper method mathModelToXML.
static String mathModelToXML(MathModel mathModel, boolean printkeys) throws XmlParseException {
String xmlString = null;
if (mathModel == null) {
throw new XmlParseException("Invalid input for BioModel: " + mathModel);
}
// NEW WAY, with XML declaration, vcml element, namespace, version #, etc.
// create root vcml element
Element vcmlElement = new Element(XMLTags.VcmlRootNodeTag);
vcmlElement.setAttribute(XMLTags.VersionTag, getEscapedSoftwareVersion());
// get mathmodel element from xmlProducer and add it to vcml root element
Xmlproducer xmlProducer = new Xmlproducer(printkeys);
Element mathElement = xmlProducer.getXML(mathModel);
vcmlElement.addContent(mathElement);
// set namespace for vcmlElement
vcmlElement = XmlUtil.setDefaultNamespace(vcmlElement, Namespace.getNamespace(XMLTags.VCML_NS));
// create xml doc with vcml root element and convert to string
Document mathDoc = new Document();
Comment docComment = new Comment("This mathmodel was generated in VCML Version " + getEscapedSoftwareVersion());
mathDoc.addContent(docComment);
mathDoc.setRootElement(vcmlElement);
xmlString = XmlUtil.xmlToString(mathDoc, false);
// xmlString = XmlUtil.xmlToString(element);
if (lg.isTraceEnabled())
lg.trace(xmlString);
return xmlString;
}
use of org.jdom.Comment in project cxf by apache.
the class StaxSerializer method writeElement.
public void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException {
// need to check if the namespace is declared before we write the
// start element because that will put the namespace in the context.
String elPrefix = e.getNamespacePrefix();
String elUri = e.getNamespaceURI();
String boundPrefix = writer.getPrefix(elUri);
boolean writeElementNS = false;
if (boundPrefix == null || !elPrefix.equals(boundPrefix)) {
writeElementNS = true;
}
writer.writeStartElement(elPrefix, e.getName(), elUri);
List<?> namespaces = e.getAdditionalNamespaces();
for (Iterator<?> itr = namespaces.iterator(); itr.hasNext(); ) {
Namespace ns = (Namespace) itr.next();
String prefix = ns.getPrefix();
String uri = ns.getURI();
writer.setPrefix(prefix, uri);
writer.writeNamespace(prefix, uri);
if (elUri.equals(uri) && elPrefix.equals(prefix)) {
writeElementNS = false;
}
}
for (Iterator<?> itr = e.getAttributes().iterator(); itr.hasNext(); ) {
Attribute attr = (Attribute) itr.next();
String attPrefix = attr.getNamespacePrefix();
String attUri = attr.getNamespaceURI();
if (attUri == null || attUri.isEmpty()) {
writer.writeAttribute(attr.getName(), attr.getValue());
} else {
writer.writeAttribute(attPrefix, attUri, attr.getName(), attr.getValue());
if (!isDeclared(writer, attPrefix, attUri)) {
if (elUri.equals(attUri) && elPrefix.equals(attPrefix)) {
if (writeElementNS) {
writer.setPrefix(attPrefix, attUri);
writer.writeNamespace(attPrefix, attUri);
writeElementNS = false;
}
} else {
writer.setPrefix(attPrefix, attUri);
writer.writeNamespace(attPrefix, attUri);
}
}
}
}
if (writeElementNS) {
if (elPrefix == null || elPrefix.length() == 0) {
writer.writeDefaultNamespace(elUri);
} else {
writer.writeNamespace(elPrefix, elUri);
}
}
for (Iterator<?> itr = e.getContent().iterator(); itr.hasNext(); ) {
Content n = (Content) itr.next();
if (n instanceof CDATA) {
writer.writeCData(n.getValue());
} else if (n instanceof Text) {
writer.writeCharacters(((Text) n).getText());
} else if (n instanceof Element) {
writeElement((Element) n, writer);
} else if (n instanceof Comment) {
writer.writeComment(n.getValue());
} else if (n instanceof EntityRef) {
// EntityRef ref = (EntityRef) n;
// writer.writeEntityRef(ref.)
}
}
writer.writeEndElement();
}
use of org.jdom.Comment in project openolat by klemens.
the class SequencerModel method init.
/**
* Initilise this JDOM doc - adding comment and setting root node
*/
protected void init() {
Document _model;
Element root = new Element(ROOT_NODE_NAME);
_model = new Document(root);
for (int i = 0; i < scorm_comments.length; i++) {
Comment comment = new Comment(scorm_comments[i]);
_model.getContent().add(0, comment);
}
this.setDocument(_model);
}
Aggregations