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 


0
solnews (3)
9/22/2008 1:48:48 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
626 Views

Similar Articles

[PageSpeed] 31

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/library/x6c1kb0s(VS.80).aspx

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
9/22/2008 1:55:22 PM
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/library/x6c1kb0s(VS.80).aspx
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/
> 
0
BartSteur (2)
9/24/2008 2:38:01 PM
On Wed, 24 Sep 2008 07:38:01 -0700, Bart Steur
<BartSteur@discussions.microsoft.com> wrote:

>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/library/x6c1kb0s(VS.80).aspx
>> 
>> -- 
>> 
>> 	Martin Honnen --- MVP XML
>> 	http://JavaScript.FAQTs.com/
>> 
0
n4jvp (1)
9/24/2008 4:09:51 PM
Reply:

Similar Artilces:

DTD validation without DOCTYPE in xml
Hi, I have some XML files that needs to be validated with a DTD but the xml files does not have the DOCTYPE tag that reference to the dtd file. Is there any way to tell XmlValidatingReader to specifically use that DTD file even when DOCTYPE is not in the xml file? Thanks. YewMing wrote: > I have some XML files that needs to be validated with a DTD but the xml > files does not have the DOCTYPE tag that reference to the dtd file. Is there > any way to tell XmlValidatingReader to specifically use that DTD file even > when DOCTYPE is not in the xml file? No, I don't thin...

e-mail to all contacts in column C #2
Thanks Ron, I'll see this with our web person and it'll hopefully work Best regards, Chri -- Chris F ----------------------------------------------------------------------- Chris FG's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=494 View this thread: http://www.excelforum.com/showthread.php?threadid=27051 ...

CListCtrl Problem: Which class does MFC new for us, CEdit or CWnd???
Hi all, I encountered a problem today about MFC's CListCtrl. I added a list control from MFC, make the first column editable(don't know how? really simple: modify 'edit labels' property of the list to 'True'), then I called CEdit* GetEditControl() which MFC provides us, I got a valid value. But when I tried to get the pointer as below, pEdit1 is always null.Why? CWnd* pWnd = m_listControl.GetEditControl(); CEdit* pEdit1 = dynamic_cast<CEdit *>(pWnd); Someone told me MFC creates a CWnd class for us but not CEdit. Can some one give me some clues? Thanks is the...

Whitespace in an Xml document
Hi, Can someone please provide sample code of how to insert and also delete whitespace from an xml document ? Thanks in advance. ...

XML editor using MFC #2
i need sourse code for xml editor using MFC and having functions parser and tree view. <chobhe.amruta@gmail.com> wrote in message news:9d750e34-ced6-4d7a-a17f-e116c0b1be30@i12g2000prf.googlegroups.com... >i need sourse code for xml editor using MFC and having functions > parser and tree view. The Ultimate Toolbox is now open source, at this link download the samples, there is a sample called "Parser" for their OXParser which shows a tree of XML elements and the contents of the element on the right side. http://www.codeproject.com/KB/MFC/UltimateToolbox.aspx -- Dav...

Advanced report. Join in XML
I have 2 types of invoices. So I need to make a join by selecting Type A and type B (custom types). Crystal can create commands, which works like views or queries, and it lets me make the link (join). My problem is that I need to specify date ranges through parameters and usually the report will receive all the records and it will apply the selection formula in the client, making the report pretty slow. Instead of creating 2 commands, is there a way to create just one?, i know how to do it in SQL, but CRM Xml is not that easy to figure it out. A command looks like this (the fetch ta...

ADO.NET writing XML file by schema using datasets
Hello, having some problems by writing XML file by XML schema. using strongly typed datasets. Schema: <?xml version="1.0" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:include schemaLocation="types.xsd" /> <xs:element name="CharactList"> <xs:complexType> <xs:sequence> <xs:elementname="Charact"maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Id" type="Id" /...

How to represent this amortization
Hello, I was wondering how I simulation an loan amortization of this type. I have a loan called 30/15. Basically it is calculated over 30 years but need to be paid in 15. What would be the best way to set it up ? Thnak you In microsoft.public.money, Thomas Poteau wrote: > >I was wondering how I simulation an loan amortization of this type. > >I have a loan called 30/15. Basically it is calculated over 30 years but >need to be paid in 15. What would be the best way to set it up ? If you know the payments, enter that data. Leave the interest blank for Money to compute. ...

Shared Xml file problem when xsd.exe is used
Hi All, I am having three XML files. One called SimpleTypes.xsd from which ComplexTypes.xsd is constructed. Then, there is another file called InformationExchangeModel.xsd that uses types in complexTypes.xsd to construct messages. I am having all sorts of problems validating these xsd files in XML spy version 5 release 4. It always complains about "undefined value for 'type' encountered". Here is the scenario SimpleTypes.xsd **************** <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema&quo...

help error message when starting up "unable to create c:\documents
Last night I began getting the following error message when I start up my computer. It might have to do with I am rebuilding my hard drive after a crash and before I got this message, I copied my old outlook file from my backup. Here is the message: "unable to create c:\documents and settings\Meg\Local Settings\Application Data\BVRP Software\NetWaiting\MoHlog.txt file" Any help is appreciated. Thanks for reading this. Got Google? => http://tinyurl.com/24h2e7o Meg wrote: > Last night I began getting the following error message when I start up my > ...

Representing times in excel without dates
Excel experts I need your help!! I am using Office XP excel and am trying to represent time in the format: AM/PM without seconds. When I put in the time [I have the cell number format set to time/"1:30PM"/Locale is English (United States)], it comes up with the date preceding the time. I have tried varying settings of time but they all come up with the date. So if I try to put in 1:00PM it would represent this as a date and leave the rest of the time as 12am. I am doing a time sheet that subtracts the hours from between two times and then adds the differences up. I want it to ...

Object or class does not support the set of events
After opening a simple Access 2007 database that worked before, I get the following error when trying to do any button that uses the on-click event. "Object or class does not support the set of events." Help gives this information: "This error occurs when an event has failed to run because Microsoft Office Access cannot evaluate the location of the logic for the event. For example, if the OnOpen property of a form is set to =[Field], this error occurs because Access expects a macro or event name to run when the event is fired." All the events are good a...

Xml.net for an XML person
Hello, If I have some XML in the following format: <Foods> <Food Name="Pizza"> <Ingredient Amount="500g">Flour</Ingredient> <Ingredient Amount="100g">Cheese</Ingredient> </Food> <Food Name="Pasta"> <Ingredient Amount="500g">Pasta</Ingredient> <Ingredient Amount="50g">Tomato Puree</Ingredient> </Food> </Foods> I want to search the XML doc for a certain type of "Food", then read the ing...

EDI / XML Options
We are a small company searching for a way to automate the reception of purchase orders and the sending of invoices and order acknowledgements. The formats that we would find acceptable are EDI-X12 or XML. What is the cheapest/best way to facilitate this need? Thanks for your suggestions. -pk ...

querying XML document
I'm trying to migrate from Access database data into XML data, and i'm having a lot of confusion. Before XML, in my ASP.NET page, i'd connect to a database, query it (SELECT * IN whatever WHERE...), and then display the results in something like a Datagrid. Very easy. How can this be done if i'm using an XML file instead of a database file? I know how to put the entire XML info into a DataSet, and then display in a DataGrid, but i don't want ALL the info in the XML file... i just want the filtered (queried) data. Am i supposed to use XSLT for this? Please someo...

260 page WORD '07 doc would not open--some kind of XML error messa
It was my first week in a new Tech Writing job at a large consulting firm. I was given a 260+ page Operational Manual that 4 prior authors had worked on. Some had very limited knowledge of WORD. I spend 3 days making edits and , of course, saving it each night. On my fourth day coming to work, I was not able to open the document. The IT Dept researched it and said it could only be retrieved by someone who 'knew XML'. They had no one and I don't know XML. I happened to explain this to an admin asst. She said I ought to send the doc to her. I did. She saved it as a 97-2003...

representative
Hi I've got a problem. I want to add a representative i my outlook beacause this person shall see my private meetings. But it's all grey, I can't add anyone. Anyone you have an idea? Thanks. Fredrik Version of Outlook? Make sure you are connected to Exchange and working in on-line mode (File-> Work Offline) -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do the Outlook Icons Mean? -Create an Office 2003 CD slipstreamed with Service Pack 1 ----- "Fredrik J´┐Żnsson" <fredrik.jonsson.trbg@telia.com> wrote in message news...

XML CDATA etc
Hello NG, I am getting some information from DB, and that data has mix html and XML tags in the content (e.g. detail on country). Basically CDATA types are mixed with regular string. Also, html tags are in escape form (e.g. > is &gt;). When I display that string I see those tags. Basically I am getting all this data as xml form and I want to find out how can I change those html tags into regular tags, and also how to remove CDATA or any instructions in the string. Is there a quick way to do that? My problem is increased as I don't know XML. Thank you, Po JohnAD wrote: &g...

use a class object for this?
I have a database that works fine... I was just trying to make it a bit more intuitive to use. Basic structure: CaseManager---(1,M)---Caseworker---(1,M)---Case---(1,M)---Paperwork Rules: Each caseworker may have no more than 10 open cases at a time. Opening a new case "spawns" a series of due dates for paperwork (based on a couple of dates. Joint Visit Date and Admit Date... these work already). Closing a case requires the scheduling of another joint visit and some specialized paperwork. Transferring a case to another social worker may only be allocated to a caseworker with fewer ...

Feeding XML to SQL2000 database
I'm starting research on how I could best approach feeding XML files to a relational database. Here's the scenario: - we receive several hundred XML files per week, all of which adhere to the same structure (we have complete control over the structure and the data that goes into the XML). - upon receipt of an XML file, we should extract the data into a Sql2000 relational database. Once that's done, we can discard the XML (only used for transporting the data). - the data in the database will be used for extensive querying - we currently have an XSD file (though we don't use it ...

How to do flush in socket programming in C++
Hi, How can I do a something like flush after calling 'send' method in CSocket class?? this because we have a Java server running in the other side which expect a flush before it responds. Pls help ...

Visual C++ and assembly
Hi...Iknow of the esistence of _asm command to incapsulate assembly code into a program written in C++. I use Visual C++ 6.0 and I am not able to use it. Can somebody give me an help? Thanks... -- ** Alan ** Your code is probably wrong but you didn't post your code or explain what exactly happens that prevents you from using it. So I'm left to simply guess here. Below is an example of a routine with inline assembler. void CMultiType::U4Rol(LPVOID p, LPVOID p2) { _asm { mov eax,[p2] mov cl,[eax] mov eax,[p] rol DWORD PTR [eax],cl } } -- Jonatha...

"Debug" import customizations xml file
Hi, I can't upload any part of the customizations.xml file. I ran the xml file in XML checker and it is valid in terms of XML. What can ruin the code of the xml file so it is not recognized by the CRM? What is the recommended way to find the errors or starting point with copying the imported customizations to the CRM? I tried to export all the customizations of a "clean" CRM, and then overrite an entity from the desired xml file but there is still a probelm. I tried to change and add the language code to the exported crm ( the new one is in english with a language pack to m...

Line Graphs with X-Axis Representing Hours
Here's the data I want to plot with multiple lines, one for A, B and C, which are quantities of things. The start time actually represents the start of an hourly window when these things accumulate. So one would read this as "Between 7:00 and 8:00, 944 things accumulated, 786 of them were B things and 158 were C things. Start A B C 07:00 944 786 158 08:00 24,445 21,802 2,643 09:00 61,540 56,505 5,035 10:00 62,938 57,748 5,190 11:00 59,737 54,864 4,873 12:00 42,903 39,228 3,675 13:00 48,001 43,873 4,128 14:00 53,206 48,839...

Inserting XML Data Into a New Table FROM VB.NET
Can anyone help me figure out how to insert data into SQL Server when a table to hold the data does not yet exist. I am able to insert data into a existing table in the following fashion. But what if the table does not exist? Appreciate any help I can get. Private Sub InsertData() Dim objSQLConn As New SqlConnection("SERVER=.;UID=sa;PWD=;DATABASE=MyTest;") Dim objAdapter As SqlDataAdapter Dim objDataRow As DataRow 'Dataset row Dim objDBRow As DataRow 'SQL Server table row Dim objDSXML As New DataSet Dim objDSDBTable As...