List of usage examples for org.dom4j Element add
void add(Namespace namespace);
Namespace
to this element. From source file:de.saar.coli.salsa.reiter.framenet.Frame.java
License:Open Source License
public Element exportToSalsaTiger() { Namespace ns = new Namespace("fd", "http://www.clt-st.de/framenet/frame-database"); Element elem = new DefaultElement("frame", ns); elem.add(new FlyweightAttribute("name", this.getName(), ns)); for (FrameElement fe : this.frameElements()) { Element fee = new DefaultElement("element", ns); fee.add(new FlyweightAttribute("name", fe.getName(), ns)); fee.add(new FlyweightAttribute("optional", String.valueOf(!fe.isCore()), ns)); elem.add(fee);//from ww w . ja va 2s . co m } return elem; }
From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.IQ.java
License:Open Source License
/** * Adds the element contained in the PacketExtension to the child element of the IQ * packet. IQ packets, unlike the other packet types, have a unique child element that * holds the packet extensions. If an extension is added to an IQ packet that does * not have a child element then an IllegalStateException will be thrown.<p> * * It is important that this is the first and last time the element contained in * PacketExtension is added to another Packet. Otherwise, a runtime error will be * thrown when trying to add the PacketExtension's element to the Packet's element. * Future modifications to the PacketExtension will be reflected in this Packet.<p> * * Note: packet extensions on IQ packets are only for use in specialized situations. * In most cases, you should only need to set the child element of the IQ. * * @param extension the PacketExtension whose element will be added to this Packet's element. *///from w w w . ja va 2 s . c o m public void addExtension(PacketExtension extension) { Element childElement = getChildElement(); if (childElement == null) { throw new IllegalStateException("Cannot add packet extension when child element is null"); } // Add the extension to the child element childElement.add(extension.getElement()); }
From source file:delphsim.model.Division.java
License:Open Source License
/** * Mtodo para volcar los datos de este objeto en uno de tipo * <CODE>org.dom4j.Element</CODE>. * @return El objeto <CODE>org.dom4j.Element</CODE>. *///from www.j a v a2 s . c om public Element volcarAXML() { Element elementoDivision = new DefaultElement("division"); elementoDivision.addAttribute("nombre", this.nombre); for (Categoria categ : this.categorias) { elementoDivision.add(categ.volcarAXML()); } return elementoDivision; }
From source file:delphsim.model.Epidemia.java
License:Open Source License
/** * Guarda la informacin de esta epidemia en el archivo pasado como * parmetro, siguiendo el esquema del .xsd de la aplicacin. * @param archivoDestino El archivo destino donde se guardar el modelo. * @throws java.io.IOException Si hay problemas al escribir en disco. * @throws org.dom4j.DocumentException Si hay problemas al crear el objeto de tipo rbol. * @throws java.lang.Exception Si se produce algn otro problema. *//*from ww w . ja v a2s . c o m*/ public void guardarXML(File archivoDestino) throws IOException, DocumentException, Exception { // Primero crear el documento dom4j con la informacin del modelo Document documento = DocumentHelper.createDocument(); // Elemento raz epidemia Element elementoEpidemia = new DefaultElement("epidemia"); documento.setRootElement(elementoEpidemia); elementoEpidemia.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); elementoEpidemia.addAttribute("xsi:noNamespaceSchemaLocation", "DelphSim1.18.xsd"); elementoEpidemia.addAttribute("unidadTiempo", this.unidadTiempo); // Elementos parmetros if (this.parametros != null) { for (Parametro param : this.parametros) { Element elementoParametro = param.volcarAXML(); elementoEpidemia.add(elementoParametro); } } // Elementos procesos if (this.procesos != null) { for (Proceso proc : this.procesos) { Element elementoProceso = proc.volcarAXML(); elementoEpidemia.add(elementoProceso); } } // Elemento poblacin Element elementoPoblacion = this.poblacion.volcarAXML(); elementoEpidemia.add(elementoPoblacion); // Elementos compartimentos for (Compartimento comp : this.compartimentos) { Element elementoCompartimento = comp.volcarAXML(); elementoEpidemia.add(elementoCompartimento); } // Luego crear el formato, stream y escritor de la salida OutputFormat formato = OutputFormat.createPrettyPrint(); formato.setEncoding("UTF-16"); formato.setIndent("\t"); formato.setNewLineAfterDeclaration(false); formato.setPadText(false); formato.setTrimText(true); formato.setXHTML(true); java.io.OutputStreamWriter salida = new java.io.OutputStreamWriter( new java.io.FileOutputStream(archivoDestino), "UTF-16"); XMLWriter escritor = new XMLWriter(salida, formato); // Y escribir escritor.write(documento); escritor.close(); }
From source file:delphsim.model.Poblacion.java
License:Open Source License
/** * Mtodo para volcar los datos de este objeto en uno de tipo * <CODE>org.dom4j.Element</CODE>. * @return El objeto <CODE>org.dom4j.Element</CODE>. *//*from www . j a v a 2 s .c o m*/ public Element volcarAXML() { Element elementoPoblacion = new DefaultElement("poblacion"); elementoPoblacion.addAttribute("nombre", this.nombre); elementoPoblacion.addAttribute("habitantes", String.valueOf(this.habitantes)); for (Division div : this.divisiones) { elementoPoblacion.add(div.volcarAXML()); } return elementoPoblacion; }
From source file:delphsim.model.Proceso.java
License:Open Source License
/** * Mtodo para volcar los datos de este objeto en uno de tipo * <CODE>org.dom4j.Element</CODE>. * @return El objeto <CODE>org.dom4j.Element</CODE>. *//*from w ww . j a va2 s . c o m*/ public Element volcarAXML() { Element elementoProceso = new DefaultElement("proceso"); elementoProceso.addAttribute("nombre", this.nombre); if (this.descripcion != null) { if (!this.descripcion.equals("")) { Element elementoDescripcion = elementoProceso.addElement("descripcion"); elementoDescripcion.setText(this.descripcion); } } for (int i = 0; i < this.procesosVinculados.size(); i++) { Element elementoProcesoVinculado = elementoProceso.addElement("procesoVinculado"); elementoProcesoVinculado.addAttribute("nombre", (String) this.procesosVinculados.get(i)); } for (int i = 0; i < this.compartimentosVinculados.size(); i++) { Element elementoCompartimentoVinculado = elementoProceso.addElement("compartimentoVinculado"); elementoCompartimentoVinculado.addAttribute("nombre", (String) this.compartimentosVinculados.get(i)); } if (this.tramosContinua != null && this.tramosContinua.length > 0) { Element elementoDefinicionContinua = elementoProceso.addElement("definicionContinua"); for (int i = 0; i < this.tramosContinua.length; i++) { elementoDefinicionContinua.add(this.getTramoContinua(i).volcarAXML()); } } return elementoProceso; }
From source file:dk.netarkivet.deploy.XmlStructure.java
License:Open Source License
/** * The current tree will be overwritten by the overwriter tree. The new branches in overwriter will be added to the * current tree. For the leafs which are present in both overwriter and current, the value in the current-leaf will * be overwritten by the overwriter-leaf. * <p>//w w w .j a v a 2 s. c om * The subtrees which exists in both the overwriter and the current tree, this function will be run recursively on * these subtrees. * * @param current The base element * @param overwriter The element to have its values overwrite the base element * @throws IllegalState If a leaf in current is about to be replaced by a tree */ @SuppressWarnings("unchecked") private void overWriting(Element current, Element overwriter) throws IllegalState { ArgumentNotValid.checkNotNull(current, "Element current"); ArgumentNotValid.checkNotNull(overwriter, "Element overwriter"); // get the attributes to be overwritten List<Element> attributes = overwriter.elements(); List<Element> addElements = new ArrayList<Element>(); // add branch if it does not exists for (Element e : attributes) { // find corresponding attribute in current element List<Element> curElems = current.elements(e.getName()); // if no such elements in current tree, add branch. if (curElems.isEmpty()) { addElements.add(e); } else { // List<Element> overElems = overwriter.elements(e.getName()); // if the lists have a 1-1 ratio, then overwrite if (curElems.size() == 1 && overElems.size() == 1) { // only one branch, thus overwrite Element curE = curElems.get(0); // if leaf overwrite value, otherwise repeat for branches. if (curE.isTextOnly()) { curE.setText(e.getText().trim()); // TODO Is this necessary } else { overWriting(curE, e); } } else { // a different amount of current branches exist (not 0). // Therefore remove the branches in current tree, // and add replacements. for (Element curE : curElems) { current.remove(curE); } // add only current branch, since the others will follow. addElements.add(e); } } } // add all the new branches to the current branch. for (Element e : addElements) { current.add(e.createCopy()); } }
From source file:dk.nsi.stamdata.replication.webservice.AtomFeedWriter.java
License:Mozilla Public License
protected void writeEntry(Element feed, String path, View record, Marshaller marshaller) throws JAXBException { Element entry = feed.addElement("atom:entry", ATOM_NS); entry.addElement("atom:id", ATOM_NS).addText(TAG_PREFIX + path + "/" + record.getOffset()); entry.addElement("atom:title", ATOM_NS); // Empty, but required by ATOM for human redability. entry.addElement("atom:updated", ATOM_NS).addText(AtomDate.toString(record.getUpdated())); // Write the actual entity inside the content tag. Element content = entry.addElement("atom:content", ATOM_NS).addAttribute("type", "application/xml"); DocumentResult dr = new DocumentResult(); marshaller.marshal(record, dr);/*from ww w . j a v a2s. c om*/ content.add(dr.getDocument().getRootElement()); }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.AbstractStudyCalendarXmlCollectionSerializer.java
License:BSD License
public Document createDocument(Collection<R> rs) { Document document = DocumentHelper.createDocument(); Element element = createCollectionRootElement(); for (R r : rs) { element.add(createElement(r, true)); }//from ww w. j a va2 s. c o m configureRootElement(element); document.add(element); return document; }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.AbstractStudyCalendarXmlSerializer.java
License:BSD License
protected void configureRootElement(Element element) { element.add(DEFAULT_NAMESPACE); element.addNamespace(XML_SCHEMA_ATTRIBUTE, XSI_NS).addAttribute("xsi:" + SCHEMA_LOCATION_ATTRIBUTE, PSC_NS + ' ' + SCHEMA_LOCATION); }