473,511 Members | 16,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help using XmlSerializer

Hi, there,

I need to read an XML file. Actually it is AddIn file in XML format for
Add-Ins in VS2005. The standard file is shown next.

My task is to deserialize it, change some element, and serialize it. I got
two problems in doing so:

1. It seems to me my code didn't get the hostapplication array.
2. How to serialize it back with the changed field?

Please help! My class definition, code to deserialize, serialize are
following:

[XmlRoot("Extensibility", Namespace =
"http://schemas.microsoft.com/AutomationExtensibility",
IsNullable = false)]
public class XMLAddIn
{
public Host[] HostApplications;
public AddIn Addin;
}

public class Host
{
public string Name;
public string Version;
}

public class AddIn
{
public string FriendlyName;
public string Description;
public string Assembly;
public string FullClassName;
public string LoadBehavior;
public string CommandPreload;
public string CommandLineSafe;
}
-----------------------Deserialize and
serialize----------------------------------
XmlSerializer serializer = new XmlSerializer(typeof(XMLAddIn));
FileStream fs = new FileStream(strAddInFile, FileMode.Open);
XMLAddIn xAddIn = (XMLAddIn)serializer.Deserialize(fs);
//change the assembly path
xAddIn.Addin.Assembly = strAssmbly;
serializer.Serialize(fs, xAddIn);
//a problem here is that the changed file like some mess code appended to my
old file. I guess it is due to my file open mode. I changed the file name,
using another writer stream, but got only partial XMLAddIn file. The
HostApplication array are apparently not read in.

<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<Extensibility
xmlns="http://schemas.microsoft.com/AutomationExtensibility">
<HostApplication>
<Name>Microsoft Visual Studio Macros</Name>
<Version>8.0</Version>
</HostApplication>
<HostApplication>
<Name>Microsoft Visual Studio</Name>
<Version>8.0</Version>
</HostApplication>
<Addin>
<FriendlyName>My great new add-in.</FriendlyName>
<Description>This add-in does it all.</Description>
<AboutBoxDetails>Copyright 2005.</AboutBoxDetails>
<AboutIconData>0000 . . . FFFF0000</AboutIconData>
<Assembly>MyNewAddin.dll</Assembly>
<FullClassName>MyNewAddin.Connect</FullClassName>
<LoadBehavior>1</LoadBehavior>
<CommandPreload>1</CommandPreload>
<CommandLineSafe>0</CommandLineSafe>
</Addin>
</Extensibility>
Apr 13 '06 #1
0 1373

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

Similar topics

5
5407
by: Stuart Robertson | last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not...
4
3121
by: Jeff T. | last post by:
Hello, I have an existing set of C# classes that encapsulate our application data. They are in a heirachy with each subclass defining more specific types of data. I would like to serialize these...
2
1554
by: yinjennytam | last post by:
Hi all I'm learning XML and .NET and I saw an example of using XmlSerializer to deserialize an XML file to get the corresponding object in memory. I found it very useful for my purpose. ...
2
1545
by: Chuck Bowling | last post by:
I'm really stumped on this. Serializing an ArrayList to XML works fine when i use built in classes but when i try storing my own classes in ArrayLists and serializing them the CLR throwns an...
1
2855
by: Opa | last post by:
Hi I'm having problem serialization an object instance which contains a public property on the object type My object hierarchy is many levels deep, so for simplicty I created to following which...
3
1762
by: Schorschi | last post by:
The following code works fine until I check the .CanDeserialize flag The exact same code in C# works, but in VB .NET? AUGH! HELP! ---------------------------------- Public Function...
1
5108
by: Yewen Tang | last post by:
I have a schema file datamodel.xsd, element "properties" is declared as a type of "baseProperty". The schema file also defines "derivedProperty" is a derived type of "baseProperty". <?xml...
10
4754
by: Henrik Dahl | last post by:
Hello! I have an xml schema which has a date typed attribute. I have used xsd.exe to create a class library for XmlSerializer. The result of XmlSerializer.Serialize(...) should be passed as the...
1
5740
by: kimtherkelsen | last post by:
Hi, I want to send XML data from a server to some clients over a network connection using the TCP/IP protocol. If I send the XMLs as byte arrays I need to insert header information in the data to...
0
7138
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
7355
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7423
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5066
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.