xstream

Reading Element attribute value using XStream

≡放荡痞女 提交于 2020-01-04 09:23:44
问题 I am not able lookup attribute value of an element. My XML is <Person> <BirthDate>2008-01-04</BirthDate> <FirstName>Affo</FirstName> <Gender tc="200">Male</Gender> <LastName></LastName> <Occupation>false</Occupation> <Age>4</Age> </Person> I am interested in <Gender tc="200">Male</Gender> . My POJO looks like this: private String FirstName; private String LastName; private String Occupation; @XStreamAsAttribute @XStreamAlias("tc") private String genderTC; private String Gender; private String

omitting xml declaration in xstream

我只是一个虾纸丫 提交于 2020-01-04 07:19:09
问题 I want to append content to xml using xstream but using xstream.toXml(obj,writer) every time I run this, it is adding xml declaration to the content, can we omit xml declaration in xstream? 回答1: In a meantime the XStream team is fixing the issue you may do workaround. Just override the createStaxWriter in StaxDriver : StaxDriver driver = new StaxDriver() { @Override public StaxWriter createStaxWriter(XMLStreamWriter out) throws XMLStreamException { //the boolean parameter controls the

How to avoid Xstream to produce xml file with &amp or &quote or similar chars?

一曲冷凌霜 提交于 2020-01-04 04:31:08
问题 I start to work with Xstream with Java. I have a list of cars named CarList . I have a car as an object named Car . XStream xstream = new XStream(new StaxDriver()); xstream.alias("Car", Car.class); xstream.alias("Cars", CarList.class); xstream.addImplicitCollection(CarList.class, "list"); xstream.toXML(list, new FileWriter(fileName+xmlExtension)); Unfortunately each time I save my file. My XML contains &quot and &amp instead of " and & . What am I doing wrong? Should I use a regex for

Optimize loading speed of xstream

我怕爱的太早我们不能终老 提交于 2020-01-02 06:16:07
问题 I felt xstream loading speed doesn't up to my requirement when I try to perform loading from the XML file. For an "database" with 10k ++ entries, it will take several minutes. The following is the entire data structure I use to serialize. Size of List (symbols and codes) will be roughly 10k ++ entries. http://jstock.cvs.sourceforge.net/viewvc/jstock/jstock/src/org/yccheok/jstock/engine/StockCodeAndSymbolDatabase.java?revision=1.11&view=markup Is there any approach I can try out, to see

Optimize loading speed of xstream

耗尽温柔 提交于 2020-01-02 06:16:07
问题 I felt xstream loading speed doesn't up to my requirement when I try to perform loading from the XML file. For an "database" with 10k ++ entries, it will take several minutes. The following is the entire data structure I use to serialize. Size of List (symbols and codes) will be roughly 10k ++ entries. http://jstock.cvs.sourceforge.net/viewvc/jstock/jstock/src/org/yccheok/jstock/engine/StockCodeAndSymbolDatabase.java?revision=1.11&view=markup Is there any approach I can try out, to see

How to disable pretty-printing(white space/newline) in XStream?

假如想象 提交于 2019-12-31 08:46:31
问题 This is how I create XStream instance for XML: XStream xstream = new XStream(); This is for JSON: private final XStream xstream = new XStream(new JsonHierarchicalStreamDriver() { public HierarchicalStreamWriter createWriter(Writer writer) { return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE); } }); Both of them are pretty-printing (indenting) the output. How can I ask the XStream to disable the pretty printing? 回答1: Thanks, your posts helped!!! Here is what I use to convert to a String.

xstream flatten an object

末鹿安然 提交于 2019-12-31 05:25:36
问题 I am trying to flatten the xml output of xstream using a converter/marshaling with no luck. For example, public class A{ public B b; public int F; public String G; } public class B{ public String C; public String D; public int E; } is output as <A> <B> <C></C> <D></D> <E></E> </B> <F></F> <G></G> </A> but I need <A> <C></C> <D></D> <E></E> <F></F> <G></G> </A> is this possible? How to get rid of B? (C, D, E are uniquely named). Thanks. My attempt thus far has been ... public void marshal

How to read list elements with attribute via XStream

血红的双手。 提交于 2019-12-30 10:28:42
问题 I'm using XStream to read below example xml file. <list> <file>/setup/x86-linux2/bin/zip.txt</file> <file type="dir">/src/bin/</file> <name>test xml</name> </list> Below is my code for reading above xml, public class ListWithConverter { public static class FileConvertor implements Converter { public boolean canConvert(final Class clazz) { return clazz.equals(MyFile.class); } public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { throw new

Converter Tutorial

和自甴很熟 提交于 2019-12-29 20:38:27
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Simple Converter Setting up a simple example This is the most basic converter... let's start with a simple Person: package com.thoughtworks.xstream.examples; public class Person { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } So let's create a person and convert it to XML... package com.thoughtworks.xstream.examples; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; public class PersonTest { public static void main(String[] args) { Person person

XStream XmlPullParserException

狂风中的少年 提交于 2019-12-29 07:41:57
问题 I'm trying to use XStream. I've added the XStream executable Jar file to my project. Executing the following command: XStream xstream = new XStream(); Is resulting in the following exception: Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException at com.thoughtworks.xstream.XStream.<init>(XStream.java:350) at xstream_test.XmlTrasformer.objectToXml(XmlTrasformer.java:56) at xstream_test.XmlTrasformer.main(XmlTrasformer.java:31) Caused by: java.lang