473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to serialize correct XML headers

All,
I am trying to generate the following header when serializing a class
to XML

<FpML
version="4-0"
xsi:type="TradeAffirmation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.fpml.org/2003/FpML-4-0
fpml-main-4-0.xsd"
xmlns="http://www.fpml.org/2003/FpML-4-0">
</FpML>

The class is currently declared as:
<System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://www.fpml.org/2003/FpML-4-0"),
_
System.Xml.Serialization.XmlRootAttribute([DataType]:="TradeAffirmation")>
_
Public Class FpML
End Class
This generates the following:
<FpML xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</FpML>

I am unsure how to get my code to generate the header correctly. Any
ideas?

Many thanks
Paul

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 12 '05 #1
1 4965
PMNorris,
This class should get you the header you're looking for:

<System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://www.fpml.org
/2003/FpML-4-0")> _
Public Class FpML
<XmlAttributeAttribute()> _
Public version As String = "4.0"

<XmlAttributeAttribute([Namespace]:="http://www.w3.org/2001/XMLSchema-instan
ce")> _
Public schemaLocation As String =
"http://www.fpml.org/2003/FpML-4-0fpml-main-4-0.xsd"

<XmlAttributeAttribute([Namespace]:="http://www.w3.org/2001/XMLSchema-instan
ce")> _
Public type As String = "TradeAffirmation"
End Class

To add the default namespace declaration, you need to pass the name of the
default namespace to the constructor of the XmlSerializer like this:
Dim ser As New XmlSerializer(GetType(FpML),
"http://www.fpml.org/2003/FpML-4-0")

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

"PMNorris" <pa*********@uk.nomura-dot-com.no-spam.invalid> wrote in message
news:3f**********@127.0.0.1...
All,
I am trying to generate the following header when serializing a class
to XML

<FpML
version="4-0"
xsi:type="TradeAffirmation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.fpml.org/2003/FpML-4-0
fpml-main-4-0.xsd"
xmlns="http://www.fpml.org/2003/FpML-4-0">
</FpML>

The class is currently declared as:
<System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://www.fpml.org
/2003/FpML-4-0"), _
System.Xml.Serialization.XmlRootAttribute([DataType]:="TradeAffirmation")> _
Public Class FpML
End Class
This generates the following:
<FpML xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</FpML>

I am unsure how to get my code to generate the header correctly. Any
ideas?

Many thanks
Paul

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: CLEAR-RCIC | last post by:
Hi, I have a class that I am trying to serialize. To simplify, I've changed the names to Baseball, Teams and Players. Here is what the XML should look like: <BaseBall> <Teams> <Team>...
14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
10
by: Dan | last post by:
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That public string SaveNewSurvey( MutualSurveyObject mso_TempObject, int i_JobID ) { string s_RootFileName;...
0
by: Ken Durden | last post by:
I'm getting the following exception coming out of a block of unmanaged C++ code. Thread executed for 1.03 sec and died with the following exception: External component has thrown an exception. ...
1
by: js | last post by:
Does anybody knows how to solve the problem? I added attribute to the following classes in Microsoft.Practices.EnterpriseLibrary.Data namespace, but I still get the error. Thanks. ...
3
by: Jeff Richardson | last post by:
This is a repost from the InfoPath news group. Hi, I am writing a SharePoint application that works with InfoPath forms. When a user submits a completed InfoPath form to a forms library my code...
1
by: Tim | last post by:
Could anyone tell me what this means and how do I correct it. Any suggestions? Thanks! Tim Richardson IT Developer and Consultant www.paladin3d.com Unable to serialize the session state. In...
2
by: =?Utf-8?B?TW91dGhPZk1hZG5lc3M=?= | last post by:
How can I add an MD5 hash to XMLSerializer.Serialize without corrupting the content of the file; then how to read it back to verify is correct? I'd like to code up something (see below) that...
3
by: Julie | last post by:
Here's the scenario (public attributes, etc. omitted for brevity): class Base { } class Derived : Base { }
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.