Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - represent XML in classes/collections (C#)

Reply
 
Old 09-22-2008   #1 (permalink)
Bart Steur


 
 

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



My System SpecsSystem Spec
Old 09-22-2008   #2 (permalink)
Martin Honnen


 
 

Re: represent XML in classes/collections (C#)

Bart Steur wrote:
Quote:

> 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/
My System SpecsSystem Spec
Old 09-24-2008   #3 (permalink)
Bart Steur


 
 

Re: represent XML in classes/collections (C#)

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:
Quote:

> Bart Steur wrote:
>
Quote:

> > 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/
>
My System SpecsSystem Spec
Old 09-24-2008   #4 (permalink)
Registered User


 
 

Re: represent XML in classes/collections (C#)

On Wed, 24 Sep 2008 07:38:01 -0700, Bart Steur
<BartSteur@xxxxxx> wrote:
Quote:

>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.

Quote:

>I'm a little stuck.
>
>Thks,
>Bart
>
>"Martin Honnen" wrote:
>
Quote:

>> Bart Steur wrote:
>>
Quote:

>> > 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/
>>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Vista bug: iconified folders use wrong icon to represent "current folder" Vista General
Icon libraries or collections Vista General
System.Collections.Generic.List<int> myList = new System.Collections.Generic.List<int>(100); .NET General
Generics and collections .NET General
How to represent newline as a character constant? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46