xml-serialization

JAXB inheritance in MOXY

我怕爱的太早我们不能终老 提交于 2019-12-19 08:53:09
问题 I have two classes: package a; class A { private <type> fieldOfClassA; // getters, and setters } package b; class B extends A{ private <type> fieldOfClassB; // getters, and setters } I want to marshal class B to an xml element and add the attribute fieldOfClassB, and fieldOfClassA from class A but it prints the following warning message during marshalling: Ignoring attribute [fieldOfClassA] on class [b.B] as no Property was generated for it. Note that the two class is from two different

Deserialize element value as string although it contains mixed content

佐手、 提交于 2019-12-19 08:10:08
问题 Assuming an XML like this: <my:Root xmlns:my="http://foo/bar"> <my:FieldBasic>content</my:FieldBasic> <my:FieldComplex> <html xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml"> <div><h1>content</h1></div> </html> </my:FieldComplex> <my:Root> and a class like: [Serializable] [XmlType(AnonymousType = true, Namespace = "http://foo/bar")] [XmlRoot(ElementName = "Root", Namespace = "http://foo/bar", IsNullable = false)] public class MyRoot { public string FieldBasic { get; set; } public

Deserialize element value as string although it contains mixed content

雨燕双飞 提交于 2019-12-19 08:09:34
问题 Assuming an XML like this: <my:Root xmlns:my="http://foo/bar"> <my:FieldBasic>content</my:FieldBasic> <my:FieldComplex> <html xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml"> <div><h1>content</h1></div> </html> </my:FieldComplex> <my:Root> and a class like: [Serializable] [XmlType(AnonymousType = true, Namespace = "http://foo/bar")] [XmlRoot(ElementName = "Root", Namespace = "http://foo/bar", IsNullable = false)] public class MyRoot { public string FieldBasic { get; set; } public

XmlSerializer , base64 encode a String member

北城余情 提交于 2019-12-19 07:52:46
问题 Consider a simple case public class Test { public String myString; } Is there any way I can tell XmlSerializer to base64 encode myString when serializing it ? 回答1: You can simply set it to be a byte[] property and it will Base64 encode it automatically: public class Test { public byte[] MyProperty {get;set;} public void SetMyProperty(string text) { MyProperty = System.Text.Encoding.Unicode.GetBytes(text); } } Test test = new Test(); test. SetMyProperty("123456789123456789"); Output:

XML Object Deserialization to Interface

左心房为你撑大大i 提交于 2019-12-19 04:49:07
问题 I have two classes SccmAction and TicketAction which both implement interface IDelivery. These classes will be transmitted on a processing queue from which I just want to pull the message and act upon the Deliver method. It seems however that I cannot deserialize to an interface because when I attempt to do so a System.NotSupportedException is thrown. From what I have gathered the XMLSerializer requires a concrete type for serialization. Does this leave me having to create an abstract class

SGEN, InternalsVisibleTo and assembly signing

寵の児 提交于 2019-12-19 04:20:40
问题 I'm trying to do something a bit unusual... I have this class Foo : public class Foo { public Foo(string name) { this.Name = name; } internal Foo() { } public string Name { get; internal set; } public int Age { get; set; } } Notice the internal setter for Name, and the internal default constructor. This would normally prevent the XML serialization, but I also marked the XML serialization assembly as "friend" with InternalsVisibleTo : [assembly: InternalsVisibleTo("TestXML2008.XmlSerializers")

Wrapping Arbitrary XML within XML

心已入冬 提交于 2019-12-19 02:58:06
问题 I need to embed arbitrary (syntactically valid) XML documents within a wrapper XML document. The embedded documents are to be regarded as mere text, they do not need to be parseable when parsing the wrapper document. I know about the "CDATA trick", but I can't use that if the inner XML document itself contains a CDATA segment, and I need to be able to embed any valid XML document. Any advice on accomplishing this--or working around the CDATA limitation--would be appreciated. 回答1: You need to

Deserialize XML without namespaces but in a class expecting namespaces

半腔热情 提交于 2019-12-18 22:14:44
问题 Duplicate: Omitting all xml namespaces when serializing an object? Not the same.. I want in the other way: Deserialize! I have a C# class as bellow: [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.portalfiscal.inf.br/nfe")] [System.Xml.Serialization

customising serialisation of java collections using xstream

喜你入骨 提交于 2019-12-18 19:31:53
问题 I have an object that needs to be serialised as XML, which contains the following field: List<String> tags = new List<String>(); XStream serialises it just fine (after some aliases) like this: <tags> <string>tagOne</string> <string>tagTwo</string> <string>tagThree</string> <string>tagFour</string> </tags> That's OK as far as it goes, but I'd like to be able to rename the <string> elements to, say, <tag> . I can't see an obvious way to do that from the alias documentation on the XStream site.

XMLWriter vs XMLDictionaryWriter

£可爱£侵袭症+ 提交于 2019-12-18 19:08:13
问题 What's the difference between XMLWriter and XMLDictionaryWriter ? In which cases is each one generally used? 回答1: XmlWriter is an abstract class of which XmlDictionaryWriter is one of the classes that inherits from it and is itself an abstract class. I am taking a stab in the dark that you want to use it with the DataContractSerializer or with de/serialization in general. The XmlDictionaryWriter is the base class used by WCF to do its de/serialization. From that I would deduce that there must