473,836 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.net XmlSerializer - not able to get the deserialize result

3 New Member
Hello,

I am trying to use XmlSerializer to deserialize an xml file and then use a loop to access the content. With the help of xsd.exe, a serializer class is generated and I am able to use that to deserialize the following xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes "?>
<layercatalog >
<category jcode="aaa">
<layerList>
<layer>
<trackNumber> 1</trackNumber>
<name>test1</name>
<DefaulityVisib ility>On</DefaulityVisibi lity>
</layer>
<layer>
<trackNumber> 2</trackNumber>
<name>test2</name>
<DefaulityVisib ility>On</DefaulityVisibi lity>
</layer>
</layerList>
</category>
<category jcode="bbb" />
<category jcode="ccc" />
<category jcode="ddd" />
<category jcode="eee" />
<category jcode="fff" />
<category jcode="ggg" />
<category jcode="hhh" />
<category jcode="iii" />
</layercatalog>

The problem is I cannot seems to get the <layer> details, I not not sure if there is something wrong with my code below:
try{

TextReader reader = new StreamReader("L ayerCatalog.xml ");
XmlSerializer serializer = new XmlSerializer(t ypeof(layercata log));
tocLayerCatalog = (layercatalog)s erializer.Deser ialize(reader);
reader.Close();
//loop each catetory
IEnumerator categoryList = tocLayerCatalog .Items.GetEnume rator();
while (categoryList.M oveNext())
{
layercatalogCat egory catetory= (layercatalogCa tegory)category List.Current;
string jcode = catetory.jcode;
//loop each layer within the category
if (catetory.layer List == null) continue;
layercatalogCat egoryLayerListL ayer[][] layerlistArray = catetory.layerL ist;
for (int i = 0; i < layerlistArray. Length; i++)
{
//Attempt to get the content of the layer tag but no luck
layercatalogCat egoryLayerListL ayer[] l = (layercatalogCa tegoryLayerList Layer[])layerlistArray[i];
IEnumerator layer = l.GetEnumerator ();
while (layer.MoveNext ())
{
layercatalogCat egoryLayerListL ayer layeritem = (layercatalogCa tegoryLayerList Layer)layer.Cur rent;
string name = layeritem.name;
}
}
}

}catch(XmlExcep tion xe){
string x= xe.Message + "XML Parse Error";

}catch(InvalidO perationExcepti on ioe){
string y = ioe.InnerExcept ion.Message + "XML Serialization Error";

}


Can someone shed some light on me, I have been stucked with this problem for awhile. Please me know if you need to cs class and I will email it to you separately.

Thanks
Apr 4 '08 #1
0 812

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1635
by: Zion Zadik | last post by:
Dear all, I have a set of c# data classes which i need to fill their data from xml files. serialization looks to be the best way to accomplish this task. Since the data classes are compiled and i don't have control on the xml structure, I tried using the xmlAttributeOverrides class, to instruct the serializer. I was able to override the attributes for the root element, but I'm having problems understanding how to deserialize arrays.
5
5432
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 create duplicate XML representations of the shared object, but instead use IDREFs to refer to the shared object. The XML I'm trying to produce is as follows (where "href" is an IDREF): <?xml version="1.0" encoding="utf-8"?> <MyRootClass...
8
3573
by: Harris Boyce | last post by:
Hello, I'm trying to use the FOR XML EXPLICIT clause with SQL Server to deserialize data from my database into a strongly-typed collection object that I will use throughout my application. I initially tested my design by building a collection in code and then serializing it to/from an XML file, which worked fine. However, I have hit a brick wall trying to restore the data from SQL Server. I originally had my collection and object
1
4325
by: Bluetears76 | last post by:
Hi I have a hirachy of classes which are Message(base), then FileMessage and ChatMessage (extended) I want to serialize the objects and when i am deserizaling i dont know if i am getting FileMessage or ChatMessage. So how to get that object and use it I have written following code for serialization public void Send(Message message) { NetworkStream netWorkStream=null;
2
942
by: magister | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different attributes, all share a base set of 4, one of the question types can have children with <option> elements, this is how the xml looks after serialization.... If you notice there is an extra <SelectionList> around the <option>'s in the final...
3
3174
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on the server (W2K3) it throws an exception. It only seems to happen when serializing/deserializing _arrays_ of a type. If I just serialize/deserialize one instance, it works fine. The exception I get is: (sorry for the word wrapping.)...
0
2313
by: William Stacey [MVP] | last post by:
Had a method that got some string info from mp3 tags in N files and serializes this class and deserializes at other side. Works ok except sometimes get chars that choke the XmlSerializer. After some digging, I found XmlSerializer chokes on 0x03 chars. It probably chokes on many others, but this one I found. It serializes ok, but chokes on deserialize on "<Field1>&#x3;</Field1>". So the questions are: 1) Why does serializer produce...
1
5779
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 distinguish the XMLs from each other in the stream of data. Is there any way to avoid this (for instance by sending SOAP telegrams))? I have tried using the XMLSerializer.Serialize(stream) to serialize the XML telegrams and send them over the...
3
3304
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 distinguish the XMLs from each other in the stream of data. Is there any way to avoid this (for instance by sending SOAP telegrams))? I have tried using the XMLSerializer.Serialize(stream) to serialize the XML telegrams and send them over the...
0
9813
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9665
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10834
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10584
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10248
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7782
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5645
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3108
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.