Last active
December 10, 2015 13:58
-
-
Save mrmichalis/4444853 to your computer and use it in GitHub Desktop.
(WORK IN PROGRESS) XML hierarchy using jdom2 - for Open Marine XML v2.0 http://wiki.openmarine.org/index.php/OpenMarineXML_Version_2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import org.jdom2.*; | |
import org.jdom2.filter.Filters; | |
import org.jdom2.input.*; | |
import org.jdom2.output.XMLOutputter; | |
import org.jdom2.xpath.XPathExpression; | |
import org.jdom2.xpath.XPathFactory; | |
import javax.print.attribute.standard.DateTimeAtCompleted; | |
import java.io.File; | |
import java.util.List; | |
import java.util.*; | |
import org.joda.time.format.DateTimeFormatter; | |
import org.joda.time.format.ISODateTimeFormat; | |
public class Main { | |
private static void log(String aMessage) { | |
System.out.println(aMessage); | |
} | |
public static void main(String[] args) throws Exception { | |
DateTimeFormatter parser2 = ISODateTimeFormat.dateTimeNoMillis(); | |
String jtdate = "2010-01-01T12:00:00+01:00"; | |
Element om = new Element("open_marine"); | |
om.setAttribute("version", "1.0"); | |
om.setAttribute("language", "english"); | |
om.setAttribute("origin", "MTM/YachtMarket/BoatsAndOutBoards"); | |
om.setAttribute("date", parser2.parseDateTime(jtdate).toString()); | |
//Offices | |
Element office = new Element("office").setAttribute("id", "") | |
.addContent(new Element("office_name")) | |
.addContent(new Element("email")) | |
.addContent(new Element("name") | |
.addContent(new Element("title")) | |
.addContent(new Element("forename")) | |
.addContent(new Element("surname"))) | |
.addContent(new Element("address")) | |
.addContent(new Element("town")) | |
.addContent(new Element("county")) | |
.addContent(new Element("country")) | |
.addContent(new Element("postcode")) | |
.addContent(new Element("daytime_phone")) | |
.addContent(new Element("evening_phone")) | |
.addContent(new Element("fax")) | |
.addContent(new Element("mobile")) | |
.addContent(new Element("website")); | |
Element off_emt = new Element("offices").addContent(office); | |
Element boat_features = new Element("boat_features") | |
.addContent(new Element("dimensions")) | |
.addContent(new Element("build")) | |
.addContent(new Element("gallery")) | |
.addContent(new Element("engine")) | |
.addContent(new Element("engine")) | |
.addContent(new Element("navigation")) | |
.addContent(new Element("accommodation")) | |
.addContent(new Element("safety_equipment")) | |
.addContent(new Element("rig_sails")) | |
.addContent(new Element("electronics")) | |
.addContent(new Element("general")) | |
.addContent(new Element("equipment")); | |
Map item = new HashMap(); | |
item.put("boat_name", ""); | |
item.put("owners_comment", ""); | |
item.put("reg_details", ""); | |
item.put("known_defects", ""); | |
item.put("range", ""); | |
item.put("last_serviced", ""); | |
item.put("passenger_capacity", ""); | |
Set st = item.entrySet(); | |
Iterator it = st.iterator(); | |
while (it.hasNext()) { | |
Map.Entry m = (Map.Entry) it.next(); | |
boat_features.addContent(new Element("item") | |
.setAttribute("name", (String) m.getKey()) | |
.setText((String) m.getValue())); | |
} | |
//Adverts | |
Element advert_media = new Element("advert_media").addContent( | |
new Element("media").setAttribute("type", "MIME Media Type") | |
.setAttribute("caption", "") | |
.setAttribute("primary", "") | |
); | |
Element advert_features = new Element("advert_features") | |
.addContent(new Element("boat_type")) | |
.addContent(new Element("boat_category")) | |
.addContent(new Element("new_or_used")) | |
.addContent(new Element("vessel_lying").setAttribute("country", "")) | |
.addContent(new Element("asking_price").setAttribute("poa", "").setAttribute("currency", "").setAttribute("vat_included", "")) | |
.addContent(new Element("marketing_descs").addContent(new Element("marketing_desc").setAttribute("language", ""))) | |
.addContent(new Element("manufacturer")) | |
.addContent(new Element("model")) | |
.addContent(new Element("other").addContent(new Element("item").setAttribute("name", "").setAttribute("label", ""))); | |
Element advert = new Element("advert").setAttribute("ref", "").setAttribute("ofice_id", "").setAttribute("status", "") | |
.addContent(advert_media) | |
.addContent(advert_features) | |
.addContent(boat_features); | |
Element ad_emt = new Element("adverts").addContent(advert); | |
om.addContent( | |
new Element("broker").setAttribute("code", "") | |
.addContent(new Element("broker_details").addContent(new Element("company_name").setText(""))) | |
.addContent(off_emt) | |
.addContent(ad_emt) | |
); | |
Document doc_open_marine = new Document(om); | |
XMLOutputter out = new XMLOutputter(); | |
out.output(doc_open_marine, System.out); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment