Refine search
public static void serialize(final String name, final Object ast) { if (name == null || name.length() == 0) return; XStream xstream = new XStream(new StaxDriver()); FileWriter astFileWriter = null; try { File astFile = astFile(name); if (astFile == null) { System.out.println("File-name for writing " + name + " AST could not be determined!"); return; } astFileWriter = new FileWriter(astFile, false); xstream.toXML(ast, astFileWriter); System.out.println("Written AST to " + name + ".xml"); } catch (Exception e) { System.out.println("Couldn't write to " + name + ".xml"); e.printStackTrace(); } finally { DefaultGroovyMethods.closeQuietly(astFileWriter); } }
public HierarchicalStreamReader createReader(InputStream in) { try { return createStaxReader(createParser(in)); } catch (XMLStreamException e) { throw new StreamException(e); } }
public HierarchicalStreamWriter createWriter(Writer out) { try { return createStaxWriter(getOutputFactory().createXMLStreamWriter(out)); } catch (XMLStreamException e) { throw new StreamException(e); } }
public StaxWriter createStaxWriter(XMLStreamWriter out, boolean writeStartEndDocument) throws XMLStreamException { return new StaxWriter(qnameMap, out, writeStartEndDocument, isRepairingNamespace(), getNameCoder()); }
public XstreamMetadataSchemeSerializer() { this.xstream = new XStream(new StaxDriver()); this.xstream.alias("metadataScheme", DcsMetadataScheme.class); this.xstream.registerConverter(new MetadataSchemeConverter()); }
@SuppressWarnings("unchecked") public static void load(final InputStream in) { if (in == null) { throw new NullPointerException("given InputStream must not be null"); } final XStream xstream = new XStream(new StaxDriver()); logs.addAll((ArrayList<CaptureLog>) xstream.fromXML(in)); }
public class Test{ public static void main(String args[]){ FileReader xmlReader = new FileReader("filePerson.xml");//File.xml will containe the xml content which you want to parse XStream stream = new XStream(new StaxDriver()); stream.alias("Person",Person.class); ArrayList<Person> person = (ArrayList<Person>) stream.fromXML(xmlReader); //If you want to retrieve then you can use iterator or foreach loop for(Person P: person){ // Write your logic }
private static XStream getxStream() { XStream xStream = new XStream(new StaxDriver()); xStream.alias("truthTable", TruthTable.class); xStream.alias("variable", Variable.class); xStream.aliasAttribute(Variable.class, "identifier", "name"); xStream.alias("result", Result.class); xStream.alias("BoolTable", BoolTableByteArray.class); xStream.alias("BoolTableEx", BoolTableExpanded.class); return xStream; }
public static XStream getXStream() { if (xStream == null) { xStream = new XStream(new StaxDriver()); xStream.alias("argument", Argument.class); xStream.alias("debate", Debate.class); xStream.alias("standaloneArgument", StandaloneArgument.class); xStream.alias("xxx.sampling.datamodel.ReasonClaimWarrantContainer", ReasonClaimWarrantContainer.class); } return xStream; } }
public static XStream createXStream() { XStream xstream = new XStream(new StaxDriver()); XStream.setupDefaultSecurity(xstream); //Setup the default hardening of types disallowed. xstream.setClassLoader(FindBugsFilter.class.getClassLoader()); for (Class modelClass : ALL_XSTREAM_TYPES) { xstream.processAnnotations(modelClass); xstream.allowTypeHierarchy(modelClass); //Build a whitelist of the class allowed } return xstream; }
/** * Creates a new {@code XStreamSerializationHandler} using a default * {@code XStream} object underneath. */ public XStreamSerializationHandler() { this(new XStream(new StaxDriver())); }
XStream xstreamin = new XStream(new StaxDriver()); //you need to add this line xstreamin.alias("account", Account.class); //then the rest of your code... Reader someReader = new FileReader("Accounts.xml"); ObjectInputStream in = xstreamin.createObjectInputStream(someReader); accountsin = (ArrayList<Account>) in.readObject(); in.close();
static XStream getInstance() { final XStream xstream = new XStreamJVM9(new PureJavaReflectionProvider(), new StaxDriver()); xstream.alias("Message", Message.class); xstream.alias("MessageProperty", MessageProperty.class); return xstream; } }
StaxDriver driver = new StaxDriver(new NoNameCoder()) { @Override public StaxWriter createStaxWriter(XMLStreamWriter out) throws XMLStreamException { // the boolean parameter controls the production of XML declaration return createStaxWriter(out, false); } }; XStream xStream = new XStream(driver); xStream.autodetectAnnotations(true);//needed to process aliases //register MyCustomReflectionConverter MyCustomReflectionConverter reflectionConverter = new MyCustomReflectionConverter (xStream.getMapper(), new SunUnsafeReflectionProvider()); xStream.registerConverter(reflectionConverter, XStream.PRIORITY_VERY_LOW);
public static String java2xml(Object obj, Class<?> T) { XStream xstream = new XStream(new StaxDriver()); xstream.processAnnotations(T); StringWriter stringWriter = new StringWriter(); xstream.marshal(obj, new PrettyPrintWriter(stringWriter)); return stringWriter.toString(); }
public static <T> String getXmlString(T data) { final StringWriter stringWriter = new StringWriter(); XStream xstream = new XStream(new StaxDriver()); xstream.autodetectAnnotations(true); xstream.marshal(data, new PrettyPrintWriter(stringWriter)); return stringWriter.toString(); }
StaxDriver drv = new StaxDriver(); XStream xstream = new XStream(drv); StringWriter strWriter = new StringWriter(); StaxWriter sw = new StaxWriter(drv.getQnameMap(), drv.getOutputFactory().createXMLStreamWriter(strWriter), false, // don't do startDocument true); // do repair namespaces xstream.marshal(ktpMessage, sw); sw.close(); String objectXml = strWriter.toString();
public void marshall(Object modelObject, XMLStreamWriter writer) throws MarshalException { try { xStream.marshal(modelObject, staxDriver.createStaxWriter(writer)); } catch (XMLStreamException ex) { throw new MarshalException(ex); } }
public HierarchicalStreamReader createReader(Reader xml) { loadLibrary(); try { return createStaxReader(createParser(xml)); } catch (XMLStreamException e) { throw new StreamException(e); } }
public XmlMediaType(Enhancer enhancer) { QNameMap qnameMap = new QNameMap(); QName qname = new QName("http://www.w3.org/2005/Atom", "atom"); qnameMap.registerMapping(qname, DefaultRelation.class); // we need the replacer because // xstream replaces an _ with __ (two underscore) more information at // http://xstream.codehaus.org/faq.html#XML_double_underscores XmlFriendlyReplacer replacer = new XmlFriendlyReplacer("$", "_"); helper = new XStreamHelper(new StaxDriver(qnameMap, replacer), enhancer); }