xml-serialization

How can I force the use of an xsi:type attribute?

纵然是瞬间 提交于 2020-01-20 07:50:28
问题 How can I force .NET's XmlSerializer to add an xsi:type="FooClass" to a member/node of type FooClass ? The scenario is a currently-released app, where in v.1 : FooClass inherits FooBaseClass FooPropertyA is on FooBaseClass FooPropertyB is on FooClass FooBaseClass is decorated with [XmlInclude(typeof(FooClass))] BazClass has member Foo of type FooBaseClass All sets of Baz.Foo are to a FooClass instance All usages of Baz.Foo expect FooPropertyB (and so a FooClass instance vs FooBaseClass) The

How can I force the use of an xsi:type attribute?

大城市里の小女人 提交于 2020-01-20 07:47:27
问题 How can I force .NET's XmlSerializer to add an xsi:type="FooClass" to a member/node of type FooClass ? The scenario is a currently-released app, where in v.1 : FooClass inherits FooBaseClass FooPropertyA is on FooBaseClass FooPropertyB is on FooClass FooBaseClass is decorated with [XmlInclude(typeof(FooClass))] BazClass has member Foo of type FooBaseClass All sets of Baz.Foo are to a FooClass instance All usages of Baz.Foo expect FooPropertyB (and so a FooClass instance vs FooBaseClass) The

Removing Wrapper Elements from XML-Serialized Array

老子叫甜甜 提交于 2020-01-19 12:45:32
问题 I am using VSTS2008 + C# + .Net 3.0. I am using below code to serialize XML, and my object contains array type property, but there some additional elements' layer (in my sample, MyInnerObject and MyObject) generated which I want to remove from the generated XML file. Any ideas? Current generated XML file, <?xml version="1.0"?> <MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <MyObjectProperty> <MyObject> <MyInnerObjectProperty>

php Dynmically format xml to php array [closed]

徘徊边缘 提交于 2020-01-17 05:26:27
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . Hi I was wondering if anyone knows a script or function that can format any xml file to a array in a specific format such as having a xml something like this (but much longer) <data> <width>3.5</width> <height>2<

Can I serialize a BitArray to XML?

会有一股神秘感。 提交于 2020-01-17 03:24:05
问题 I have a business class which I need to serialize to xml. It has a BitArray property. I have decorated it with [XmlAttribute] but the serialization is failing with To be XML serializable, types which inherit from ICollection must have an implementation of Add(System.Boolean) at all levels of their inheritance hierarchy. System.Collections.BitArray does not implement Add(System.Boolean). I am not sure whether its possible to serialize to xml? If not what would be an efficient means of

Error while XML serializing an object

孤者浪人 提交于 2020-01-16 15:35:52
问题 I thought my class conformed to all the XML serialization requirements. Here is part of the error message. InnerException: System.InvalidOperationException HResult=-2146233079 Message=A circular reference was detected while serializing an object of type TheseusAndTheMinotaur.LevelDesigner.ModelMap. Source=System.Xml StackTrace: at System.Xml.Serialization.XmlSerializationWriter.WriteStartElement(String name, String ns, Object o, Boolean writePrefixed, XmlSerializerNamespaces xmlns) at

JAXB - Parse element into string

帅比萌擦擦* 提交于 2020-01-16 04:33:08
问题 Is there a way to parse part of an XML message into a String keeping it in XML format? Example... <person> <name>John Doe</name> <age>24</age> <address> <street>bailey</street> <city>boston</city> </address> </person> public class Person { @XmlElement private NameClass name; @XmlElement private int age; @XmlElement private String address; ... } public class NameClass { ... } Where I want the entire address element to be kept in XML format and parsed as a String. 回答1: You can use

Deserialize XML with multiple types

谁都会走 提交于 2020-01-15 09:48:28
问题 I'm trying to deserialize XML where some same name tags have different xsi types: <user-defined-data-row> <field name="entity"> <field-value xsi:type="field-text-valueType"> <value>Test</value> </field-value> </field> <field name="expiry_date"> <field-value xsi:type="field-date-valueType"> <value>2001-10-07</value> </field-value> </field> </user-defined-data-row> This is easily achieved by deserializing the xml into this model: [XmlRoot(ElementName = "field-value", Namespace = "http://www

InvalidOperationException on a PostAsXmlAsync call

*爱你&永不变心* 提交于 2020-01-14 14:08:09
问题 When calling HttpClient method PostAsXmlAsync, I'm getting the following InvalidOperationException: Token EndElement in state End Document would result in an invalid XML document. Why am I getting this exception? var user = new RXGRequestUser(); var client = new HttpClient(); var response = await client.PostAsXmlAsync(@"myurl.com", user); RXGRequestUser: public class RXGRequestUser : IXmlSerializable { public string Username { get; set; } public string Password { get; set; } public string

Serializing XML with strange namespaces?

随声附和 提交于 2020-01-14 13:58:13
问题 Question: How does the class for the serialization of this XML content look ? <?xml version="1.0" encoding="utf-8"?> <vcc:CreateTextSearchResponse xmlns:vcc="urn:veloconnect:catalog-1.1" xmlns:vct="urn:veloconnect:transaction-1.0"> <vct:BuyersID>12345</vct:BuyersID> <vct:ResponseCode>200</vct:ResponseCode> <vct:TransactionID>225</vct:TransactionID> <vct:StatusCode>2</vct:StatusCode> <vct:IsTest>false</vct:IsTest> <vcc:TotalCount>3876</vcc:TotalCount> </vcc:CreateTextSearchResponse> If I let