xml-serialization

How to add an XML namespace (xmlns) when serializing an object to XML

泪湿孤枕 提交于 2019-12-22 04:05:49
问题 I'm serializing Objects to XML with the help of XStream. How do I tell XStream to insert an xmlns to the XML output of my object? As an example, I have this simple object I want to serialize: @XStreamAlias(value="domain") public class Domain { @XStreamAsAttribute private String type; private String os; (...) } How do I achieve exactly the following output with XStream? <domain type="kvm" xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> <os>linux</os> </domain> 回答1: Alternatively, this

XML Serialization of the default values of optional attributes

孤街浪徒 提交于 2019-12-22 04:05:32
问题 I have a set of classes build using xsd.exe, and I am trying to serialise them. However, an attribute is not being included in the resulting XML. Here is part of the schema where the problem lies. <xsd:element name="Widget"> <xsd:complexType> /* sequence removed for brevity */ <xsd:attribute name="Version" type="Version" use="optional" default="1.1"/> </xsd:complexType> </xsd:element> <xsd:simpleType name="Version"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="1.0"/> <xsd

Invalid XML Character During Unmarshall

人盡茶涼 提交于 2019-12-22 03:55:54
问题 I am marshalling objects to XML file using encoding "UTF-8". It generates file successfully. But when I try to unmarshal it back, there is an error: An invalid XML character (Unicode: 0x{2}) was found in the value of attribute "{1}" and element is "0" The character is 0x1A or \u001a, which is valid in UTF-8 but illegal in XML. Marshaller in JAXB allows writing this character into XML file, but Unmarshaller cannot parse it back. I tried to use another encoding (UTF-16, ASCII, etc) but still

Invalid XML Character During Unmarshall

你说的曾经没有我的故事 提交于 2019-12-22 03:55:10
问题 I am marshalling objects to XML file using encoding "UTF-8". It generates file successfully. But when I try to unmarshal it back, there is an error: An invalid XML character (Unicode: 0x{2}) was found in the value of attribute "{1}" and element is "0" The character is 0x1A or \u001a, which is valid in UTF-8 but illegal in XML. Marshaller in JAXB allows writing this character into XML file, but Unmarshaller cannot parse it back. I tried to use another encoding (UTF-16, ASCII, etc) but still

JAXB XML Object Marshalling without namespace prefixes

本小妞迷上赌 提交于 2019-12-22 03:24:46
问题 Im working on a java project where i need to read some objects from an XML file, do some processing which will alter the object´s atributes and then write the Object to another XML file. For that purpose, i am using JAXB with its marshalling and unmarshalling capabilities, each of them in a method, like this: private MyObject unmarshallXMLFile(String file) { MyObject t=null; try { jc = JAXBContext.newInstance("foo.bar"); Unmarshaller unmarshaller = jc.createUnmarshaller(); SchemaFactory sf =

Serialization and Deserialization into an XML file, C#

半腔热情 提交于 2019-12-21 23:12:21
问题 I have the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication28 { class Program { static void Main() { List<string> dirs = FileHelper.GetFilesRecursive(@"c:\Documents and Settings\bob.smith\Desktop\Test"); foreach (string p in dirs) { Console.WriteLine(p); } //Write Count Console.WriteLine("Count: {0}", dirs.Count); Console.Read(); } static class FileHelper { public static List<string>

.NET WCF serialization issues

坚强是说给别人听的谎言 提交于 2019-12-21 17:24:58
问题 The situation: system A is supposed to expose SOAP 1.2 web service for system B to call. In order for A to know what the message looks like, B sent an XSD to A describing the contents of the message. A generated the stubs using the .NET xsd.exe tool, created the simple webservice around this and the job was done. However; when B calls this webservice, A refuses to serialize the SOAP/XML content to the generated proxy class instances. I realize this must be down to the way the serialization is

How do I get the value from a specific node in an XML file?

安稳与你 提交于 2019-12-21 12:59:49
问题 From this XML code: <?xml version="1.0" encoding="utf-8"?> <Tabel> <Member> <Naam>Cruciatum</Naam> <Kills>1000</Kills> <Deaths>10</Deaths> <KD>100</KD> </Member> <Member> <Naam>Ghostbullet93</Naam> <Kills>10</Kills> <Deaths>1</Deaths> <KD>10</KD> </Member> </Tabel> How can I get (for example) the 10 next to <Kills> ? I've tried multiple things without any success. One of the ideas I had was using this code: Dim doc = XDocument.Load("C:\members.xml") Dim members = From m In doc.Element("Tabel"

how to use XmlAttributeOverrides when serializing an array?

人盡茶涼 提交于 2019-12-21 12:52:40
问题 I have an array called _updatedComponents of objects that are of class NetworkComponent. I have to serialize it in the way that the name and namespace of the root element (=array) is changed and individual NetworkComponent-item's name is changed to component. I have a code below that causes an exception: System.InvalidOperationException: There was an error reflecting type 'ComponentSyncService.NetworkComponent[]'. ---> System.InvalidOperationException: XmlRoot and XmlType attributes may not

how to use XmlAttributeOverrides when serializing an array?

三世轮回 提交于 2019-12-21 12:52:07
问题 I have an array called _updatedComponents of objects that are of class NetworkComponent. I have to serialize it in the way that the name and namespace of the root element (=array) is changed and individual NetworkComponent-item's name is changed to component. I have a code below that causes an exception: System.InvalidOperationException: There was an error reflecting type 'ComponentSyncService.NetworkComponent[]'. ---> System.InvalidOperationException: XmlRoot and XmlType attributes may not