Can't apply XmlType attribute when impl. IXmlSerializable

Hello!

I can't apply the XmlType attribute when I implement IXmlSerializable.
There is an exception being thrown:

Unhandled Exception: System.InvalidOperationException: There was an error
generating the XML document. ---> System.InvalidOperationException: There
was an error reflecting type 'Start'. --->
System.InvalidOperationException: XML attributes may not be specified for
the type Start.

The problem is, that without specifying XmlType, then I get this xml
output:

<?xml version="1.0" encoding="ibm850"?>
<LandXml xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="LandXML">
  <Line line="line">
    <Start start="start" xmlns="">
      <a>7</a>
      <b>4</b>
      <c>0</c>name</Start>
  </Line>
</LandXml>

Here, the element Start is within a default namespace. I want it to be
within the LandXML namespace, so that the xml would be:

<?xml version="1.0" encoding="ibm850"?>
<LandXml xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="LandXML">
  <Line line="line">
    <Start start="start">
      <a>7</a>
      <b>4</b>
      <c>0</c>name</Start>
  </Line>
</LandXml>

Here is the (minimal) code I'm working on. The XmlType attribute for the
class Start has been commented out. Try uncommenting it.

using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

//[XmlType(Namespace="LandXML")]
public class Start : Point3D
{
}

public class End : Point3D
{
}

public class Point3D : Point2D
{
   public double c = rnd.Next(10);

   public override void WriteXml(XmlWriter w)
   {
      w.WriteAttributeString("start", s);
      w.WriteElementString("a", null, a.ToString());
      w.WriteElementString("b", null, b.ToString());
      w.WriteElementString("c", null, c.ToString());
      w.WriteChars(Name.ToCharArray(), 0, Name.Length);
   }

   public override XmlSchema GetSchema()
   {
      // TODO:  Add Start.GetSchema implementation
      return null;
   }

   public override void ReadXml(XmlReader reader)
   {
      // TODO:  Add Start.ReadXml implementation
   }
}

public class Point2D : IXmlSerializable
{
   public static Random rnd = new Random();
   public double a = rnd.Next(10), b = rnd.Next(10);

   [XmlAttribute]
   public string s = "start";

   [XmlText]
   public string Name
   {
      get { return "name"; }
      set { }
   }

   public virtual void WriteXml(XmlWriter w)
   {
      w.WriteAttributeString("start", s);
      w.WriteElementString("a", null, a.ToString());
      w.WriteElementString("b", null, b.ToString());
      w.WriteChars(Name.ToCharArray(), 0, Name.Length);
   }

   public virtual XmlSchema GetSchema()
   {
      // TODO:  Add Start.GetSchema implementation
      return null;
   }

   public virtual void ReadXml(XmlReader reader)
   {
      // TODO:  Add Start.ReadXml implementation
   }
}

public class Line : IXmlSerializable
{
   [XmlAttribute]
   public string s = "line";
   public Start start = new Start();
   public void WriteXml(XmlWriter w)
   {
      w.WriteAttributeString("line", s);
      //! serialize start
      XmlSerializer ser = new XmlSerializer(typeof(Start));
      ser.Serialize(w, start);
   }

   public void ReadXml(XmlReader r)
   {
   }

   public XmlSchema GetSchema()
   {
      return null;
   }
}

[XmlRoot(Namespace="LandXML")]
public  class LandXml
{
   public LandXml() { line = new Line(); }

   [XmlElement(ElementName="Line")]
   public Line line;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
   }

   public Test()
   {
      Console.WriteLine("** Serializing LandXml:");
      XmlSerializer ser = new XmlSerializer(typeof(LandXml));
      ser.Serialize(Console.Out, new LandXml());
      Console.Write("\n");
   }
}


I realize this is an advanced question, since even implementing
IXmlSerializable is unsupported. I would be really interested in knowing if
this works with .Net Framework 2.0. Any of the MVPs know anything?
Thanks in advance!

-- 
Daniel
0
someone913 (592)
2/28/2005 7:59:34 AM
dotnet.xml 7266 articles. 0 followers. Follow

0 Replies
961 Views

Similar Articles

[PageSpeed] 37

Reply:

Similar Artilces:

How to preserve root node attributes on serialization
It seems that XML Serializatoin automatically puts certain XSD attributs in the root node. How can I control the root node attributes emitted to something more custom so I can preserve my schema link? Alex wrote: > It seems that XML Serializatoin automatically puts certain XSD attributs in > the root node. How can I control the root node attributes emitted to > something more custom so I can preserve my schema link? Just create public fields and reflect them to these attributes using usual XmlAttribute attribute. -- Oleg Tkachenko http://www.tkachenko.com/blog Multiconn Techno...

How do I apply a combo box to multiple cells in Excel so that it .
I would like to apply a combo drop down box in Excel. However I only want the box to appear when the cursor is over the cell can anyone offer me some help on this matter? Thank you, Dwain Hi Dwain, Perhaps you are looking for Data Validation, available on the Data menu. See Debra Dalgleish's tutorial at: http://www.contextures.com/xlDataVal01.html --- Regards, Norman "DB" <DB@discussions.microsoft.com> wrote in message news:6939ADC2-CF1C-46AA-B163-BEE27E23356A@microsoft.com... >I would like to apply a combo drop down box in Excel. However I only w...

Apply view to all folders
Greetings, A user has numerous folders created under her Inbox in Outlook 2000. She woule like to create a custom view and then apply it to all folders automatically. I can create a custom view easily, but can't find a way to apply it to all folders other than on a one-by-one basis. Is there a way to apply the view to all folders at one time? Thanks much, Justin You can't apply it to all at once - unless you customize the Messages view. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Coauthor, OneNote 2003 for Windows (Visual QuickStart Gu...

Serializing a simple class to an attribute.
Hello everyone, I am fairly new to C#, but I have done my fair share of C++ and XML. I am experimenting with C# serialization and I have a nagging problem. I have an XML that looks like this... <Order deliveryDate="2003-07-04T00:00:00" customerId="123"> I want the deliveryDate attibute to come from a member class..... like in the code below. Seems like I cannot create a class that will serialize itself into an attribute. So my $100 question is, how can I create a class thqat will serialize itself into a single atttribute? Thank you! ...

view applied?
What does the following WLM beta message mean? View applied not connected to imap4.xxxxxx.co.uk I had already clicked on this account and a couple of emails were downloaded. ...

M2005 Cannot Apply Epayment To Invoice
This is a multi-part message in MIME format. ------=_NextPart_000_000C_01C4AD73.81F30C10 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I create invoices for payments from customers. I have those = automatically charged to their bank accounts and credited to my bank = account. When the payments hit my bank account and are downloaded into = Money, I go into the transaction and enter "Payment For Invoice" and = then try to go to the apply payment to an invoice screen but a nice = little pop up comes up in Money 2005 that says &qu...

I've applied a Fill and now can't see the gridlines....
Does anyone know how to show the Gridlines through a fill? I've searched and searched but can't find the answer, yet the silly thing is I know it can be done as I have done it before (by accident) Any help mostgratefully received! bestregards, Tim Apply borders... In article <62E1EA83-287A-4FE3-BEC6-7C0155EA1850@microsoft.com>, "FizzyBunghole" <FizzyBunghole@discussions.microsoft.com> wrote: > Does anyone know how to show the Gridlines through a fill? I've searched and > searched but can't find the answer, yet the silly thing is I know it c...

Unable to create attribute thorough metadata service
Hi, I am getting "The request failed with HTTP status 401: Unauthorized." error message when I am Trying to create picklist attribute through metadata Webservice in Console Application. I have written the below code. Please help. metadatacrmsdk.CrmAuthenticationToken token = new metadatacrmsdk.CrmAuthenticationToken(); token.OrganizationName = "DEVWIPRO2"; // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication. token.AuthenticationType = 0; // Create the metadata Web service. metadatacrmsdk.MetadataService...

Cross Apply problem
How do I get the desired result for the following: SOURCE TABLE: USSoilLyr FIELDS: TAXOR PARTSIZE PCT_R Alfisols ashy 60 Alfisols ashy 57 Alfisols ashy 38 Alfisols clayey 85 Alfisols clayey 79 Andisols medial 50 Andisols medial 36 DESIRED RESULT (TARGET TABLE): T_Order FIELDS: TAXOR PARTSIZE PCT_R Alfisols ashy AVG(60+57+38) Alfisols clayey Avg(85+79) Andisols medial Avg(50+36) My T-SQL Code, as follows, returns wrong calculations when I manually check the results. UPDATE T_Order SET ...

Change the datatype of an entity attribute
Hello, I had created a new 'business required' attribute for the Quote Product entity with the datatype 'nvarchar(Length:4; Format: Text)'. The Problem is now that i have to allow only numeric inputs so I want to change the datatype to 'int'. But I can=B4t because the datatype field in the attribute view is readonly yet. Have anybody an idea to solve this problem? Thanks in advance and best regards Nillefiz I dont think it is posible - I'v had the same problem. You can log on to the database, but I don't beliv it can be done direct from CRM // Morten ni...

Install V10 HR after applying service pack 3
I am currently on V10, SP3 and now have purchased the HR module. I am not sure of the steps I need to take to load the HR module (we have the V10 DVD that is not sp3) Are these my steps? 1. Load the HR module from V10 DVD on SQL Server install (I was told previously to use the Add/Remove programs option and change but it still asks for the DVD) 2. Do I need to reload SP3 on server install? 3. Then load the HR module (from V10 dvd) on additional workstations? If I have to re run the SP3 I am concerned it is going to take hours to complete like original instal of SP3 If anyone has a...

Apply Multicurrency Invoices in Bank Management
I oppened a ticket to know why I cant apply Multicurrency Invoices to payment transactions in Bank Managment as it is available in Payable Management. I've been suggested to post a suggestion for that. Simply, while doing a payment in Bank Management. If the Chequebook Currency is diffrenet than the invoices currencies that you are paying againist, then you can't apply these invoices. Thus, you cant see them in the remittance advice. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestio...

CRMService missing action attribute in form tag while sending mail
Hi I have a requirement of sending a form over email - I have used CRMservice to send emails Now i have put a form tag with action attribute as <form name='frmAction1' action='contactus@xyz.com'> but when this form tag is put in HTML and supplied as email body to CRMservice to create emails the action attribute is getting stripped Let me know any suggestions ...

Payables issue with Applied Payments and Void Check
Hi, We had a user a number of months ago apply a number of Credit Memos from a vendor to a large invoice while creating a check. Apparently the check was then void, without a normal check number leaving us with "REMIT0000000000xx" as the reference to it. We now have a situation where the large invoice and all of the credits are still showing in the system as open. The individual credit memos do not show as having amounts applied, but when we try to apply them we're told that the amount is already applied. Everything seems to be stuck in limbo, with no way to post to resol...

unposted applied credits
how can list all unposted applied credits in AR. Thanks, Scott If you have SmartList Builder, you could use it to create a SmartList based on the Cash receipts work file. "Scott Rusoff" wrote: > how can list all unposted applied credits in AR. > > Thanks, > Scott > Create a report off RM10201 (RM Cash Receipts Work File). Add a restriction where Current Transaction Amount <> Original Transaction Amount. "Scott Rusoff" wrote: > how can list all unposted applied credits in AR. > > Thanks, > Scott > Which smartlist contains t...

How to apply a weighting
I'm trying to apply a weighting to my teams to allow for experience and size I have 3 teams which are different sizes and are different skill levels. Level 5 is the lowest skill level and level 1 being the highest skill level. Team size/level5/level4/level3/level2/level1 6/3/2/0/1/0 10/2/3/4/0/1 7/0/2/3/1/1 How do I apply a weighting to these numbers to allow for team size and experience. Can I do this using sumproduct? I tried looking at this but cant get my fragile little mind around it Thanks in advance. -- Homer J ---------------------------------------------------------------...

Assigning XML string as the content of an attribute
Hi. I want to assign an XML string to an XML attribute. This XML string must undergo "escape" conversion so that the < and & symbols are converted in to escaped equivalents. Does the .Net library have a conversion method that does this? Note that I want to construct the resulting XML string myself without having to use an XmlDocument. E.g. string myXml = "<root><record/><record/></root>"; string myDoc = "<doc myXml='" + Converter.escapeMyXml (myXml ) + "'/>"; -- McGeeky http://mcgeeky.blogspot.com ...

Mass apply or batch apply sales documents?
Is there any way to avoid manually applying payments one by one? Our current process is that we have a cash receipt batch of payments that have declined, and on a daily basis, it is reauthorized. When the payments are approved, the payments are posted without applying the payment to the invoice first. We are using GP 10. Thanks, Erin Erin, There are several third party programs that address this issue very well. Do a search on the internet and you shall find them. Best regards, Leslie Vail "Erin Black-Mitchell" wrote: > Is there any way to ...

bit attribute
I've created a custom bit attribute and I need to get the possible values a user would be able to select from through the api. For example, for a radio button with the values "Yes" or "No". I need to get the values "Yes and No". The bit attribute can be a radio button or a check box. For a picklist, i can get the data i need by accessing the PicklistAttributeMetadata. Assitance would be appreciated. Thanks..Steve G'day Steve!! I have some code that could help you there, however you could save yourself a lot of time if you know how to read the PICKLIST...

Force user to fill attribute
Hi, I have WS with WSDL file which describe some type, let's say an animalType. I define in the code a "name" property to that type. I want that property to be required, means that if the consumer of the WS try to send animalType without specifiying the name, an error will be raised. Is it possible? Thanks. ...

Apply CF to Row after CF was applied to Column
Can someone please help me? I've read through the postings and the help files but still can't seem to figure out how to do this. I've applied conditional formatting to the J column of my spreadsheet so that if there's any text listed the cell turns yellow. What I'd like is if not only the cell but the row, from A:O turned yellow also. How do you do that? I'm using 07. Any help in English walking me through the steps or a hint toward the appropriate post would be greatly appreciated. Cuz I aint figrin it out on myown! Thanks in advance! --Dax...

Does the Junk email filtering rules apply to RSS feeds?
Answer required! No. RSS feeds are voluntary and if you don't like them, you just delete them from reaching you. This is the same with newsgroups. If you don't like the insults in these newsgroups, you don't subscribe to them. PERIOD. Nobody send you these things to your mailbox. It is you who is getting them for your own consumption. With email it is completely different. You get spam even if you didn't want them so you need filters for them. Hope this helps. Jackel Jhon wrote: > > Answer required! Jackel Jhon wrote: > Answer required!...

GPO not applied
Dear all I have the following situation: 2 DC with Windows Server 2003, 1 Terminal Server with Windows Server 2003 and 2 Terminal Server with Windows Server 2008. For different clients I have different GPOs. When I login as user A (from client group A with GPO A) to each of these 3 Terminal Server the GPO applies successfully. When I login as user B (from client group B with GPO B) to each of those 3 Terminal Server the GPO does not apply. I notice that I have the error in event viewer: 1053: Windows cannot determine the user or computer name. (The specified user does no...

No image when stationery applied via code
Hi I am applying stationary to my outgoing email message when sending mail via code. The exact code is given at the end. The problem is that the image doe snot appear in the stationery at the other end. What is the problem and how can I get the image to accompany the mail as part of the stationary? I am running the code from within MS Access. Many Thanks Regards Code ==== Set OutlookApp = New Outlook.Application Set EM = OutlookApp.CreateItem(olMailItem) With EM .To = "user@company.com" .Subject = "Any Subject" .HTMLBody = HTMLTextAndSignature(...

Apply patch
--wihuwnzlron Content-Type: multipart/related; boundary="yrdtlhhpgluxil"; type="multipart/alternative" --yrdtlhhpgluxil Content-Type: multipart/alternative; boundary="gnolhsghonsbmhfpk" --gnolhsghonsbmhfpk Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Microsoft Partner this is the latest version of security update, the "September 2003, Cumulative Patch" update which resolves all known security vulnerabilities affecting MS Internet Explorer, MS Outlook and MS Outlook Express as well as three newly discovered vulnerabilities. In...