473,394 Members | 1,889 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,394 software developers and data experts.

represent XML in classes/collections (C#)

Hi

I want to represent the following XML structure in a class or classes.
<CATEGORY NAME="BASE">
<PERSON NAME="PERSON">M. Johnson</PERSON>
<JOBTITLE NAME="JOBTITLE">Director</JOBTITLE>
<SUBCATEGORY NAME="SUB">
<BUILDING NAME="BUILDING">Paris</BUILDING>
<FLOOR NAME="FLOOR">5</FLOOR>
<ROOM NAME="ROOM">6A</ROOM>
</SUBCATEGORY>
<PHONE NAME="PHONE">555-5626</PHONE>
<SCALE NAME="SCALE">C</SCALE>
</CATEGORY>

Where SUBCATEGORY is in fact a CATEGORY in a CATEGORY, but a SUBCATEGORY
cannot contain another SUBCATEGORY (only 1 level deep)

The tags specified are an example. This is not a fixed set of tags. It's
even possible that no SUBCATEGORY is specified.

I'm looking for a generic 'class solution'

thks
Bart
Sep 22 '08 #1
3 2817
Bart Steur wrote:
I want to represent the following XML structure in a class or classes.
Try xsd.exe to first infer a schema from the XML, then to infer classes
from the schema:
http://msdn.microsoft.com/en-us/libr...0s(VS.80).aspx

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 22 '08 #2
Ha Martin,

Maybe I wasn't clear enough. I don't want a class representation of the XML
itself, I want a class/collection structure that can create/maintain the
following XML structure:

<category>
<attribute_n/>
...
<subcategory_n>
<attribute_n/>
...
</subcategory_n>
...
<attribute_n/>
...
<subcategory_n>
<attribute_n/>
...
</subcategory_n>
...
<attribute_n/>
...
</category>

Within that class I want to add/remove attributes and subcategories and
attributes within subcategories. The number of attributes within a category
is unknown, the number of attributes with a subcategory is unknown, also the
number of subcategories within a category is unknown.

What does that class look like, and do I need collections, or something else.

I'm a little stuck.

Thks,
Bart

"Martin Honnen" wrote:
Bart Steur wrote:
I want to represent the following XML structure in a class or classes.

Try xsd.exe to first infer a schema from the XML, then to infer classes
from the schema:
http://msdn.microsoft.com/en-us/libr...0s(VS.80).aspx

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 24 '08 #3
On Wed, 24 Sep 2008 07:38:01 -0700, Bart Steur
<Ba*******@discussions.microsoft.comwrote:
>Ha Martin,

Maybe I wasn't clear enough. I don't want a class representation of the XML
itself, I want a class/collection structure that can create/maintain the
following XML structure:

<category>
<attribute_n/>
...
<subcategory_n>
<attribute_n/>
...
</subcategory_n>
...
<attribute_n/>
...
<subcategory_n>
<attribute_n/>
...
</subcategory_n>
...
<attribute_n/>
...
</category>

Within that class I want to add/remove attributes and subcategories and
attributes within subcategories. The number of attributes within a category
is unknown, the number of attributes with a subcategory is unknown, also the
number of subcategories within a category is unknown.

What does that class look like, and do I need collections, or something else.
The class will look a lot like the XmlNode type with a collection of
attributes and a collection of childnodes. It seems likely there will
be more than a single category. If this is the case the container
starts looking like an XML document.

Depending upon your actual needs you might consider writing a type
which maintains the data in a private/protected XmlDocument member.
The type's public methods provide a clean interface through which the
document and data may be manipulated. Private/protected helper methods
can perform the various CRUD operations behind the pretty interface.

i.e.
public class MyDataContainer
{
private XmlDocument doc;
...
public bool AddSubcategory(
string CategoryName,
string SubcategoryName,
string[] SubcategoryAttributes)
{...}
...
}

It may be possible to do something similar with the XDocument family.

regards
A.G.

>I'm a little stuck.

Thks,
Bart

"Martin Honnen" wrote:
>Bart Steur wrote:
I want to represent the following XML structure in a class or classes.

Try xsd.exe to first infer a schema from the XML, then to infer classes
from the schema:
http://msdn.microsoft.com/en-us/libr...0s(VS.80).aspx

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 24 '08 #4

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

Similar topics

3
by: toki | last post by:
public class Form1 : System.Windows.Forms.Form { MyClass myclass; public Form1() { myclass = new MyClass(); } }
12
by: Wes McCaslin | last post by:
I have a question about concrete and abstract classes. what are the differances? can you explain them to me. I have started an advance Visual Studio.Net class and I am having a hard time...
3
by: Paul | last post by:
Hello, I'm upgrading a small single user app to VB.NET and have a few questions about loading classes & collections classes with the data from a one to many dataset structure. I'm serializing...
1
by: Raju Joseph | last post by:
Hi All, We are in the process of developing an N-Tier app using VB.NET. We are extensively using classes (entity objects) in our design. Further, most of the times, we do have to specify nested...
3
by: Dave | last post by:
Please - anyone that can help. I am getting confusing results while trying to expose a collection from a web service. I have a webservice in which a web method accepts a collection as a...
5
by: M Harris | last post by:
We are developing an application (using .Net in MS Studio 2003 using the Access jet engine as a backend) that is doing quite a bit of number crunching. The first part of the application was...
5
by: wshaer | last post by:
Hi This is the task: and these are my classes: public class Engine{ // Declare the varibles
4
by: Aidy | last post by:
In .net 1.1 we'd have a whole bunch of collections for each of our classes. So we'd have "ProductCollection", "UserCollection" etc etc, each a strongly-typed collection for that user. I know in...
7
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
Can someone explain a few things about collections to me. In C# 2 generics, you can create a collection class by inheriting from System.Collections.ObjectModel.Collection. Using this you can...
3
by: Bart Steur | last post by:
Hi I want to represent the following XML structure in a class or classes. <CATEGORY NAME="BASE"> <PERSON NAME="PERSON">M. Johnson</PERSON> <JOBTITLE NAME="JOBTITLE">Director</JOBTITLE>...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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.