xml-serialization

Allow .NET WebApi to disregard DOCTYPE declaration

余生长醉 提交于 2019-12-14 02:59:12
问题 I am trying to deserialize XML to an object through a WebApi Method. I have the following class: [XmlRoot(IsNullable = false)] public class MyObject { [XmlElement("Name")] public string Name {get;set;} } And the following Method in a WebApi Controller. [HttpPost] public HttpResponseMessage UpdateMyObject(MyObject model) { //do something with the model } I am using the XmlSerializer by setting the following in the startup of the Web Project: config.Formatters.XmlFormatter.UseXmlSerializer =

Unable to unmarshal shadow class variable in jaxb

好久不见. 提交于 2019-12-14 02:43:37
问题 @XmlSeeAlso(Employee.class) public abstract class Person { protected String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Employee extends Person { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } and in my public static main(), i setName("John") and marshal it to an xml. This generates an XML :-

How to have an attribute on an element of type string

天大地大妈咪最大 提交于 2019-12-14 02:33:45
问题 If I have [XmlElement(ElementName = "Title")] public string Title; How can i include an attribute in title without declaring a class (its type is just a string)?? so that when i serialize using XML serializer, the output is something like this: <Movie> <Title x:uid="movie_001">Armagedon</Title> <Date>010101</Date> <Movie> and not like this: <Movie> <Title x:uid="movie_001" MovieTile="Armagedon"\> <Date>010101</Date> <Movie> 回答1: I don't think this is possible without having Title be a custom

Set xml header with XmlSerializer

瘦欲@ 提交于 2019-12-14 02:27:07
问题 My xml looks like that... I have this fixed header I need to append to any xml file I am writing, an idea how do I do that? **<?xml version="1.0"?> <!DOCTYPE profile SYSTEM "criteria_profile.dtd">** <profile type="INTERC" id="6 " description="MushonTest" state="" lastchuser="MUSHON" lastchtmstmp="20130903132018 " createuser="MUSHON"> <root> <node type="A"> <item description="crite3"> <field>AUTHCKMAN<criterion sign="I" opt="EQ" low="cl" high=""/> </field> <field>JOBCLASS<criterion sign="I"

Is there a way to avoid self-closing tags when using XML Serialization?

假装没事ソ 提交于 2019-12-14 00:56:26
问题 I am working with VB.NET and I am facing a problem with XML serialization. When empty values exists in the object I am serializing, the XML file contains the following tags: <tagName/> instead of: <tagName></tagName> I know that it's the same, but I want the start tag to close appropriately. 回答1: They are the same and it makes no difference. Any parser or reader understands the meaning, so why is this so important to change? I find the current behavior better as it will result in smaller

Ignore a property when serializing to XML

泪湿孤枕 提交于 2019-12-13 19:20:24
问题 I have a base class that has MANY big classes inside it. For example, Let's say Person class. Inside it, there is a Payment Class, inside there is a CreditCard class, and so on... I am trying to serialize Person class, and I would like to exclude certain classes inside it. In this example, I am trying to serialize Person class and ignore the ENTIRE payment class. This is what I did so far, but it's not working. Can you guys help me figure out how I can achieve this? Thanks XmlAttributes att =

XStream different alias for same class (Map.class) for different fields

戏子无情 提交于 2019-12-13 19:15:25
问题 I am using XStream to convert a Java class which has fields of the type java.util.Map. I have a converter for java.util.Map which displays the key of the Map as an xml element and the value of the map as the value for the xml element. I have registered the converter using registerConverter method. When I perform the marshalling, I get the following output. <cart account_id="123" shift_id="456" account_postings_id="641"> <supervisor_id>555</supervisor_id> <payments> <map sequence="1"> <amount

how to iterate through xml child elements

大城市里の小女人 提交于 2019-12-13 18:35:13
问题 I have this xml tag code which looks as follows: <FeatureLayerExtension> <WhereString>(ZONE ='A') or (ZONE ='V')</WhereString> <OutFields>ZONE</OutFields> <UniqueDataCount>2</UniqueDataCount> <UniqueValueRenderer> <SimpleFillSymbol Color="White" Fill="Yellow" Width="1.5" Fvalue ='A' /> <SimpleFillSymbol Color="White" Fill="Green" Width="1.5" Fvalue ='V' /> </UniqueValueRenderer> </FeatureLayerExtension> I use this in .Cs page with help of serialization in the following way: if (projectMap

Adding a node to same xml file on sd card under its root tag in android

隐身守侯 提交于 2019-12-13 18:22:12
问题 Hello friends I have this code in which I am writing an xml file to my sd card: public class SingleItemView extends Activity { File newxmlfile = new File(Environment.getExternalStorageDirectory() + "/testfinal.xml"); TextView txtmdname,txtutcost,txtdesc,txtmodno; // Declare Variables String mdname; String utcost; String desc; String modno; String flag; String toolscat; String tan; int number; String numberOfItems; ProgressDialog mProgressDialog; Bitmap bmImg = null; ImageView addToCartButton;

ASP.NET Web API is serializing with underscore

妖精的绣舞 提交于 2019-12-13 18:11:51
问题 I have the following simple code in an ApiController: public Version Get() { var version = new System.Version(1, 1, 0, 0); return version; } which results in the following: json {"_Major":1,"_Minor":1,"_Build":0,"_Revision":0} xml <Version xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/System"> <_Build>0</_Build> <_Major>1</_Major> <_Minor>1</_Minor> <_Revision>0</_Revision> </Version> Please note the properties are preceded with an _ .