simple namespace deserialize problem

Hello

I want to deserialize the following xml

<anyRoot xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ogsa.globus.org/any-service"><QName>abc</QName></anyRoot

using

TextReader tr = new StreamReader("c:\\test.xml")
anyRootType rootType = (anyRootType)serializer.Deserialize(tr)
tr.Close()

but always get the exception

Message: There is an error in XML document (1, 2)
Message: <anyRoot xmlns='http://ogsa.globus.org/any-service'> was not expected

If I remove
xmlns="http://ogsa.globus.org/any-service
from the xml file everything works fine.
What could be the reason? Thanks for any help

Andre
0
anonymous (74719)
2/11/2004 4:01:07 AM
dotnet.xml 7266 articles. 0 followers. Follow

4 Replies
334 Views

Similar Articles

[PageSpeed] 28

Andre,

What does the class that you instantiate the serializer for look like?

-- 
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor

"Andre" <anonymous@discussions.microsoft.com> wrote in message
news:95B11509-59B3-4AD8-9CCD-426B46CAD3CD@microsoft.com...
> Hello,
>
> I want to deserialize the following xml:
>
> <anyRoot xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://ogsa.globus.org/any-service"><QName>abc</QName></anyRoot>
>
> using:
>
> TextReader tr = new StreamReader("c:\\test.xml");
> anyRootType rootType = (anyRootType)serializer.Deserialize(tr);
> tr.Close();
>
> but always get the exception:
>
> Message: There is an error in XML document (1, 2).
> Message: <anyRoot xmlns='http://ogsa.globus.org/any-service'> was not
expected.
>
> If I remove:
> xmlns="http://ogsa.globus.org/any-service"
> from the xml file everything works fine.
> What could be the reason? Thanks for any help.
>
> Andre


0
2/11/2004 5:14:51 AM
Christoph,

Here is the full code listing. As mentioned before everything works fine as long as the xmlns="http://ogsa.globus.org/agreement-factory-service" is NOT included in the xml.
Thanks for any comments.

Andre

test.xml:
<SupportedAgreementType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ogsa.globus.org/agreement-factory-service"><QName>agreement01</QName><price><QName>price_per_invocation</QName></price><serviceLevel><QName>service_level</QName></serviceLevel><qosLevel><QName>qos_level</QName></qosLevel><minRequests><QName>minimal_requests</QName></minRequests></SupportedAgreementType>

The c# code:

class Class1
{
    [STAThread]
    static void Main(string[] args)
	{
      	                XmlSerializer serializer = new XmlSerializer(typeof(SupportedAgreementType));
		TextReader tr = new StreamReader("c:\\test.xml");
		SupportedAgreementType sat = (SupportedAgreementType)serializer.Deserialize(tr);
		tr.Close();
	}
}

public class SupportedAgreementType
{
	private string _qname; 
	SupportedTermType _price;
	SupportedTermType _serviceLevel;
	SupportedTermType _qosLevel;
	SupportedTermType _minRequests;

	public string QName
	{
		get{ return _qname;  }
		set{ _qname = value; }
	}

	public SupportedTermType price
	{
		get{ return _price;  }
		set{ _price = value; }
	}

	public SupportedTermType serviceLevel
	{
		get{ return _serviceLevel;  }
		set{ _serviceLevel = value; }
	}

	public SupportedTermType qosLevel
	{
		get{ return _qosLevel;  }
		set{ _qosLevel = value; }
	}

	public SupportedTermType minRequests
	{
		get{ return _minRequests;  }
		set{ _minRequests = value; }
	}
}

public class SupportedTermType
{
	private string _qname;
	private string _termValue;
		
	public string QName
	{
		get{ return _qname;  }
		set{ _qname = value; }
	}

	public string termValue
	{
		get{ return _termValue;  }
		set{ _termValue = value; }
	}
}

0
anonymous (74719)
2/11/2004 10:06:09 PM
The serializer doesn't know about the Xml namespace since the .NET Type
doesn't declare it.

You need to add the following attributes to make sure the serializer will
consider the namespace:

[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://ogsa.globus.org
/agreement-factory-service")]
[System.Xml.Serialization.XmlRootAttribute("SupportedAgreementType",
Namespace="http://ogsa.globus.org/agreement-factory-service",
Nullable=false)]

-- 
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor

"Andre" <anonymous@discussions.microsoft.com> wrote in message
news:9BD239CC-26F0-4FA2-AF9F-895C01746B35@microsoft.com...
> Christoph,
>
> Here is the full code listing. As mentioned before everything works fine
as long as the xmlns="http://ogsa.globus.org/agreement-factory-service" is
NOT included in the xml.
> Thanks for any comments.
>
> Andre
>
> test.xml:
> <SupportedAgreementType xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://ogsa.globus.org/agreement-factory-service"><QName>agreement01<
/QName><price><QName>price_per_invocation</QName></price><serviceLevel><QNam
e>service_level</QName></serviceLevel><qosLevel><QName>qos_level</QName></qo
sLevel><minRequests><QName>minimal_requests</QName></minRequests></Supported
AgreementType>
>
> The c# code:
>
> class Class1
> {
>     [STAThread]
>     static void Main(string[] args)
> {
>                       XmlSerializer serializer = new
XmlSerializer(typeof(SupportedAgreementType));
> TextReader tr = new StreamReader("c:\\test.xml");
> SupportedAgreementType sat =
(SupportedAgreementType)serializer.Deserialize(tr);
> tr.Close();
> }
> }
>
> public class SupportedAgreementType
> {
> private string _qname;
> SupportedTermType _price;
> SupportedTermType _serviceLevel;
> SupportedTermType _qosLevel;
> SupportedTermType _minRequests;
>
> public string QName
> {
> get{ return _qname;  }
> set{ _qname = value; }
> }
>
> public SupportedTermType price
> {
> get{ return _price;  }
> set{ _price = value; }
> }
>
> public SupportedTermType serviceLevel
> {
> get{ return _serviceLevel;  }
> set{ _serviceLevel = value; }
> }
>
> public SupportedTermType qosLevel
> {
> get{ return _qosLevel;  }
> set{ _qosLevel = value; }
> }
>
> public SupportedTermType minRequests
> {
> get{ return _minRequests;  }
> set{ _minRequests = value; }
> }
> }
>
> public class SupportedTermType
> {
> private string _qname;
> private string _termValue;
>
> public string QName
> {
> get{ return _qname;  }
> set{ _qname = value; }
> }
>
> public string termValue
> {
> get{ return _termValue;  }
> set{ _termValue = value; }
> }
> }
>


0
2/12/2004 2:53:04 AM
Thanks Christoph for the quick help, It works fine now. Best regards, Andre
0
anonymous (74719)
2/12/2004 4:41:06 AM
Reply:

Similar Artilces:

Form Viewing Problem
Hi, I've created a new Form for logging in phone calls. I've created the worksheets and relationships. My problem is I was able to view (and use) my Form yesterday, but then added a new field. Now, under the Form tab, I can only view the Design View, not the Form or Layout View (it only shows the header and there is a small black dash in the top right section of where the body should be). The same is true for the Phone Log Worksheet (all my previously entered data is there). If I open the Copy of the Form, I can see all the Views. I tried to remove the new field hoping th...

install CRM domain account problem
Hi, I am trying to install MS CRM 1.2 on a W2K3 server. I am already logged into the W2K3 box as a domain admin (and the domain admins is already a member of the local admin group as well) BUT I still get this error! --------------------------- Microsoft CRM Server Setup --------------------------- You must be a member of the Domain Admins group to install Microsoft CRM. Make sure that this computer is joined to the domain and you are logged on with a domain administrator account. ----- My domain controller is a W2K box. Any idea why Windows keeps giving me this error when I am already comp...

Problem beim Empfangen
Seit 21.12. habe ich mit dem Empfangen meiner Emails Probleme: 1. Es werden immer wieder Emails angezeigt, welche ich schon gelesen bzw. gel�scht habe 2. Es kommt diese Fehlermeldung: Die Verbindung wurde unerwartet vom Server beendet. M�gliche Ursachen sind Server- oder Netzwerkprobleme oder eine lange inaktive Phase. Konto: 'pop3.web.de (1)', Server: 'pop3.web.de', Protokoll: POP3, Port: 110, Secure (SSL): Nein, Fehlernummer: 0x800CCC0F Kann mir bitte jemand helfen? Vicky "Unexpectedly terminated" is usually caused by interference from an antiv...

Simple graph
I have a chart with zip codes and a population rate. ZIP RATE 80001 2.34 80002 1.23 80003 1.23 I want to make a chart that has the rate on the x axis and the number of times that rate occurs on the y axis. | | | * | | * |_________________________________ | | 1.23 2.34 Thank you. I will assume the ZIP and RATE stuff is in A1:B200 (labels in row 1) Label in G1 to read RATE (but leave it empty for now), label in H2 to read COUNT Make a list of rates in G2:G20 (say) In H2 =COUNTIF($B$2:$B$200,G2) Copy down the row Select H1:G20 and make a...

Fundamental Problem With CDs
I must be doing something fundamentally wrong with the way I work with my CDs in Money 2005, and I'd appreciate some advice. I opened a one month CD a couple of years ago and I have just let the bank renew it automatically. When I enter the renewal information from the bank, Money requires me to "redeem" the CD, then "buy" a new CD. This is counter-intuitive since the bank uses the same account number. For example, I have to "redeem" CD Account 123 and "buy" a new CD Account 123 #2. Then a month later I "redeem" CD Account 123 #2 and...

Simple Simple Simple
Just started Excel (again) and need to make an easy speadsheet fo calculating square inches. Column A: Height Column B: Legnth Column C: Total Tags per 16 x 24 Column D: Cost per tag Figures I know: each sheet cost me $9.98. each sheet is 16 x 24 inches What I want to do is enter the Height, enter the Length and have th total (sum) be entered into columns C and D. I can't believe I forgot how to enter formulas. Any help will b appreciated. Thank you, Crai -- Message posted from http://www.ExcelForum.com Hi Craig, One Way, might be better ways but this'll work: List the colou...

Simple help with implementing Outlook-like GUI
Hi All. I am an experienced unix programmer who sometimes has to do something in the windows world, and always has newbie-questions. Basically I want to write an application program that looks like outlook in that it has nice icons down the left hand side that choose the content of the main area in the right hand side. So I started the MFC App wizard, and got me a SDI program with a CLeftFrame (CTreeView) and a CMainFrame (CFrameWnd). Then I prepared the following snippet of code to draw the buttons: // Create a pushbutton CBitmapButton* pmyButton; pmyButton = new CB...

A WMP Problem?
This problem started a few days ago. I can't recall what I might have done. Up to that point if I cllicked on an internet link for a movie clip either Quick Time or WMP automatically opened and played the file. If I downloaded a WMV file and saved it WMP opened the file and played it whenever I clicked on the saved file. Now if I click on a file on a website Quick TIme works as usual but WMP will not automatically start and open/play the file. Instead, I get an empty page with a note in the bottom saying "done." No video. If I save the file it opens just fine wi...

Simple Query Wizard hangs
I am using Access 2003 When I initiate the "Simple Query Wizard", I am presented with the first screen - "What fields do you want in your query" When I click on the pulldown list to select a table, I get the following message: "The expression On Get Focus you entered as the event property setting produced the following error: the text you entered isn't an item in the list * the expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]. * There may have been an error evaluating the function, event, or macro&q...

Problem with Date Formatting
I am importing a text file with dates in the format 3/1/05. I need the data formatted as DD-MMM-YYYY. I can get this for all dates EXCEPT where the leading zero has been dropped off the day, such as 3/1/05. Can anyone suggest how to do this in Excel? ...

Redundant namespace descriptors
Using this target schema: http://sourcepost.sytes.net/sourcepost/sourceview.aspx?source_id=24480 I generate this xml: http://sourcepost.sytes.net/sourcepost/sourceview.aspx?source_id=24481 using the VS editor. For the boolean attribute 'Selected' in the Answer tags a complete namespace is redefined xmlns:d3p1="http://tempuri.org/QuizData.xsd." This seems pretty redundant to me and would lead to some awful code bloat in a large file. Is there any way to fix this so that I not generating a new namespace definition in every tag? ...

protection problem
When I protect a work sheet, the tab key and the left/right arrows only work within the same row and will not go to the next cell in the next row. The Enter and up/down arrows do not work at all. To input data on the sheet, you have to keep using the mouse to go to the needed cell in each row. On a sedcond worksheet that is almost identical, the keys work correctly. Why does one sheet work and the next doesn't? ...

Calender problems
For some reason when I download a bill that I have paid and reconciled, it does not update in the calender. So, for some bills they are crossed out and marked as paid, and others are saying that they are days overdue. But these particular bills do not show up in the bills section as paid? And when I go to "account details" it shows the payment as being paid?? Any advice would be helpfull...I'm not overly concerned as I tend to ignore the calender, but just a little confused. Thanks, Jennifer ...

Simple hack to get $500 to your home. 06-05-10
Simple hack to get $500 to your home at http://uknews.tk Due to high security risks,i have hidden the cheque link in an image. in that website on left side below search box, click on image and enter your name and address where you want to receive your cheque.please dont tell to anyone. ...

I Need a Simple Sales Software
Hello, I am looking for software to keep track of my prospects, customers, and the notes of the sales process. I spend about one hour a day on sales and marketing, so I prefer a simple and inexpensive software. Maximizer, Outlook, Act, and Goldmine seem made for the full-time professional salesperson. Please let me know if what I am looking for exists. Best Regards, T.I. ...

Exchange ReInstallation Problem
Ok. I might have posted a similar question before, but now some things have changed so I decided to start a new thread. I have a SBS 2003(SP1) running on my server. That also includes Exchange 2003. Here is the problem, when I tried to install SP for Exchange, it told me that "Exchange 2003 must be present to install this update". I spoke to someone at microsoft about a hotfix install for exchange that also did not see the server and they told me to reinstall exchange on top of existing one. Ok, so I stayed behind last night to do the install, but ran into problems. Whe...

Strange problem, Help is appreciated
dear all i am administering Exchange 5.5 SP 3 on NT 4 SP6a the problem is that all of the suddent of the email accounts configured as firstname.lastname@mydomain.com does not receive any email nither from the internet nor from exchange, the owner of this mail box is configured in outlook as an internet account, if some one sent to the address above he will receive a time out message from his ISP that the mail could not be sent and will try to send it within 4 days, the very strange thing is if i change any letter from the email it can send and receive. Any suggesstion about what might happene...

Make it more simple or intuitive to do simple things
I appreciate the fact that applications are becoming more versatile and able to do things that we hardly thought possible in the past but I feel that in this added complexity you are losing sight of the need to do simple things easily without resorting to trial and error or consulting "help" which often anyhow doesn't lead one straight to the solution! An example is how to produce a chart with a series of months i.e Jan Feb Mar etc appearing on the X axis. This is no doubt something that resulted naturally in the first versions of Excel charts or in a competitor's ea...

Simple public folder permission problem
I have a public task list folder. However even though I have given everyone "Author" priviledges and full control of the directory, users cannot update the tasks (although they can create new ones). The changes to tasks get reset to their original values. Where should I look to fix this problem? Brian How did you grant Author Access, via Outlook or ESM? What do you meanyou gave them full control of the directory? "Brian Taylor" <taylorb@newsgroups.nospam> wrote in message news:e2hwumGrEHA.1160@tk2msftngp13.phx.gbl... > I have a public task list folder. Ho...

What is simple text?
When creating a custom list that includes a column of accounting formated data, I get an error message that 'fields without simple text will be ignored'. The result is all other data except the accounting formatted data. Help!!!! I suppose it means without the currency symbol and thousands delimiters. On Fri, 8 Apr 2005 11:01:04 -0700, TexMas <TexMas@discussions.microsoft.com> wrote: >When creating a custom list that includes a column of accounting formated >data, I get an error message that 'fields without simple text will be >ignored'. The result is ...

simple question
Okay, I have a very simple question. Where do the old posts go after they run off the last page of this newsgroup? Sometimes I would like to refer to a post that I remember seeing in October, but is no longer on the current section. The search function seems to only search current posts as well. If anyone has some input please email me at joep@siboneylg.com Thanks kindly. have you tried google groups, they keep archived old posts: http://groups.google.co.uk/groups?q=microsoft.public.greatplains&hl=en "Joe Proehl" <joep@siboneylg.com> wrote in message news:099701c5...

Duplex Mail Merge Problem with 2007 (& 03)
Background: I have been merging forever including duplexing postcards. Current: I need to duplex print name tags on Avery 5392 4x3" cards. Front and back will be identical. My problem is that Pub 2003 has the bug that won't allow you to merge duplex "custom" size publications. (However, you can with the postcard template). Next Step: In an effort to get around the issue, I downloaded the 2007 Beta 2 (and installed the Technical Refresh). I create the document based on the template (6 per page) but when I get to the point to print, I get in trouble. I select &q...

Simple Macro is not so simple
Hi all, I am trying to record a macro which will automatically perform the insert > comment function to a selected cell. Should be easy right? Alas no Danny There's sample code on my web site, for inserting comments: http://www.contextures.com/xlcomments03.html Aardvark wrote: > Hi all, > > I am trying to record a macro which will automatically perform the insert > > comment function to a selected cell. Should be easy right? Alas no -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html Wow! Nice one :-) Thank you M...

I have a problem with "Freeze Panes"
I have a problem with "Freeze Panes." I have a shared Excel file, where the top row is frozen. Every once in a while, the entire page becomes frozen. Everyone that uses this Excel file has denied unfreezing and refreezing the panes. Does anyone know how this could be occurring, if people aren't unfreezing and refreezing the panes? Do you use data|Filter|autofilter? Say you filter the data and you see row 1 (Headers) and row 82 (rows 2-81 are hidden by the filter). If you apply window|freeze panes with the activecell A82 (looks like the first visible cell under the headers...

try
I use try catch mechanism and notice (in the debugger) that whenever the control arrives to the catch section, I get an access violation (error 0xC0000005)even though it skips this section immediately. I pass compilation without any problems and the program runs fine but crashes every few hours. Does anyone have any idea? Thanks Gil You are writing to a memory you are not supposed to write. -- Vipin Aravind http://www.explorewindows.com "Gil" <gil@blinkit.com> wrote in message news:er3tTiHsGHA.4472@TK2MSFTNGP02.phx.gbl... >I use try catch mechanism and notice (in...