xml-binding

JAXB and property ordering

自古美人都是妖i 提交于 2019-11-27 11:45:21
I want the serialized XML output from my Java class to honor the ordering of the properties in the Java class. It seems that JAXB orders alphabetically. I can override this by using @XmlType with propOrder and specifying ALL of the properties, but I have a class with many properties and these are not yet finalized. I read that specifying an empty propOrder would do it but it don't. My example class: package test; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; @XmlRootElement //@XmlType(propOrder={"company"

Remove 'standalone=“yes”' from generated XML

家住魔仙堡 提交于 2019-11-27 02:53:29
Do you know of a JAXB setting to prevent standalone="yes" from being generated in the resulting XML? <?xml version="1.0" encoding="UTF-8" standalone="yes"?> Sam marshaller.setProperty("com.sun.xml.bind.xmlDeclaration", Boolean.FALSE); can be used to have no <?xml version="1.0" encoding="UTF-8" standalone="yes"?> However i wouldnt consider this best practice. so_mv in JAXB that is part of JDK1.6 marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); WarFox You can either use marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); or marshaller.setProperty("com.sun.xml.bind

JAXB and property ordering

◇◆丶佛笑我妖孽 提交于 2019-11-26 15:46:51
问题 I want the serialized XML output from my Java class to honor the ordering of the properties in the Java class. It seems that JAXB orders alphabetically. I can override this by using @XmlType with propOrder and specifying ALL of the properties, but I have a class with many properties and these are not yet finalized. I read that specifying an empty propOrder would do it but it don't. My example class: package test; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation

Remove &#39;standalone=“yes”&#39; from generated XML

白昼怎懂夜的黑 提交于 2019-11-26 12:35:58
问题 Do you know of a JAXB setting to prevent standalone=\"yes\" from being generated in the resulting XML? <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> 回答1: marshaller.setProperty("com.sun.xml.bind.xmlDeclaration", Boolean.FALSE); can be used to have no <?xml version="1.0" encoding="UTF-8" standalone="yes"?> However i wouldnt consider this best practice. 回答2: in JAXB that is part of JDK1.6 marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); 回答3: You can either use

how to derive xml element name from an attribute value of a class using annotations?

最后都变了- 提交于 2019-11-26 09:58:03
问题 I have properties that have ids and values and a name. Can I represent all those with a single class using XmlElement/XmlArray C# annotations? I would like to derive the xml element name from the class attribute name ; my class would look like: public class Property { public string name; //could be enum public int id; public string value; } e.g: new Property(\"property1name\",2,\"testvalue\"); new Property(\"property2name\",10,\"anothervalue\"); I would like to have xml that looks like: