473,399 Members | 2,858 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,399 software developers and data experts.

.net XmlSerializer - not able to get the deserialize result

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>
<DefaulityVisibility>On</DefaulityVisibility>
</layer>
<layer>
<trackNumber>2</trackNumber>
<name>test2</name>
<DefaulityVisibility>On</DefaulityVisibility>
</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("LayerCatalog.xml");
XmlSerializer serializer = new XmlSerializer(typeof(layercatalog));
tocLayerCatalog = (layercatalog)serializer.Deserialize(reader);
reader.Close();
//loop each catetory
IEnumerator categoryList = tocLayerCatalog.Items.GetEnumerator();
while (categoryList.MoveNext())
{
layercatalogCategory catetory= (layercatalogCategory)categoryList.Current;
string jcode = catetory.jcode;
//loop each layer within the category
if (catetory.layerList == null) continue;
layercatalogCategoryLayerListLayer[][] layerlistArray = catetory.layerList;
for (int i = 0; i < layerlistArray.Length; i++)
{
//Attempt to get the content of the layer tag but no luck
layercatalogCategoryLayerListLayer[] l = (layercatalogCategoryLayerListLayer[])layerlistArray[i];
IEnumerator layer = l.GetEnumerator();
while (layer.MoveNext())
{
layercatalogCategoryLayerListLayer layeritem = (layercatalogCategoryLayerListLayer)layer.Current;
string name = layeritem.name;
}
}
}

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

}catch(InvalidOperationException ioe){
string y = ioe.InnerException.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 795

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

Similar topics

4
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...
5
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...
8
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...
1
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...
2
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...
3
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...
0
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...
1
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...
3
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.