XML Deserialization

Hello Guys,

I have tried to use the xsd.exe tool to generate a class for the
following Oracle-generated xml sample but always fail to get it right
when I try to change oracle xml elements names to the class's names,
specifically I'm not sure how to do it for the ROWSET and ROW part of

Being very new to the serialization/deserialization business I'm sure
this is very easy to implement for someone with a bit of more
knowledge of it, can some help me please.

I have created 2 classes for for Department and Employee:

    class Department
        string DepID { set; get; }
        string DepName { set; get; }
        Employee[] Employees { set; get; }

    class Employee
        string DepID { set; get; }
        string DepName { set; get; }

But this fails to work as the system complains it cannot find the ROW
element, which to be honest I don't know how to tell the system to
ignore it. I know xsd.exe would help me but it generates lots of
unwanted data plus leaves me to sort the names manually. I would
really like to learn how to do this without relying on an automation

Many thanks,


<?xml version="1.0"?>
2/13/2010 8:10:02 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 23

Maya wrote:

> But this fails to work as the system complains it cannot find the ROW
> element, which to be honest I don't know how to tell the system to
> ignore it. I know xsd.exe would help me but it generates lots of
> unwanted data plus leaves me to sort the names manually. I would
> really like to learn how to do this without relying on an automation
> tool.

If you want to learn that stuff then I nevertheless think that starting 
with using xsd.exe first to infer a schema and then to generate classes 
is a good approach as that gives you working code you can then play 
with/adapt and always resort to if some change doesn't work out.

If your ROWSET element contains multiple ROW elements then the class 
representing the ROWSET needs a property in the form of an array or list 
of a class representing a ROW element, the same as you have tried for 
the EMPLOYEES element. So you need one more class at least to represent 
ROW elements and then the Department class needs a property to store a 
collection of ROW elements where you move the properties you currently 
have in the Department class to the new class you create for ROW elements.


	Martin Honnen --- MVP XML
2/13/2010 10:57:52 AM

Similar Artilces:

XML Aesthetics
Hi folks, If I have a .NET XmlDocument object into which I've imported a full node from another document, I'm running into a formatting issue. The problem arises when the imported node is nested at a different level in its source document than its destination document (among other things) which causes the indenting/whitespace characteristics of the resulting document to be 'off'. Not the most show-stopping problem in the world I know, but I was surprised to find that there wasn't a member of XmlDocument that 're-normalised' the content into correct nested i...

Apply the CRM SBE wizard XML file
I ran the Microsoft CRM SBE configuration wizard and took the option of saving the info to an XML file to be applied latter. Now for the life of me I can't figure out how to "apply it latter". Anyone know how this is supposed to work? Gary I stupidly went through the wizard a second time, thinking it would prompt me at the IMPORT phase and let me specify my saved XML file. But it didn't now if I run it again I get a message that it can only be run once! Arghhhh. Is there ANYWAY to get it to let me run it again? I tried going to a command prompt and running it ...

XML Data
Hi, I want to read news data from http://rss.com.com/2547-1_3-0-20.xml into a DataSet. The result DataSet will probably have more than one table for item nodes and one table for channel. What would be the easiest/efficient way to do that ? Can VS.NET generate schema automatically based on XML Data ? Thanks, Ali http://aspnet.4guysfromrolla.com/articles/031903-1.aspx discusses exactly this topic. -D example ASP.NET page that creates a DataSet from this thing: <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Xml" %> <script languag...

XML Centric application advice
Hi, I'm attempting to write a web application that helps us keep track of our PC fleet. Data on our PC's is collected by a 3rd party application that outputs XML. I want to load this data into Sql Server, and allow people to query it via a web application. My previous experience in this kind of this is using PHP and Oracle, but now that I've moved to .Net, I want to do things the right way. After making a few false starts, I've used the xsd inference tools to generate a C# class that can de-serialize the XML documents. >From there I've manually created an SQL Server ...

traverse xml document nodes
I have the following code that uses xquery to return search results from an xml doc. dim xmlString as string xmlString = "siteMapNode/siteMapNode/siteMapNode/siteMapNode[contains(translate(@title,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'), '" + txtSearchCriteria.Text.ToUpper() + "')]" nodeList=root.SelectNodes(xmlString,nsmgr) It all works great as long as I specify the level in which to search: siteMapNode/siteMapNode/siteMapNode/siteMapNode but I want to search all levels of the doc. siteMapNode siteMapNode/si...

I'm trying to deserialize my xml type as an array w/o a declared namespace, but none of the Serialization Attribute classes help. Where can I find info on how to build a deserializer that will create arrays? I think you will need to create a wrapper class and suck the array out of that wrapper. "jsh02_nova@hotmail.com" <jsh02novahotmailcom@discussions.microsoft.com> wrote in message news:89A83E5F-EC8D-4EB2-A737-5FFF86FCCC14@microsoft.com... > I'm trying to deserialize my xml type as an array w/o a declared > namespace, > but none of the Serialization Att...

transform xml from client to server
Hello, I am using .net. I need to transfer table data of an html (client) to the server. I don't know if best thing to do is (and correct me if I'm wrong) : 1) translate the table to xml code via javascript. 2) use the xml text as a parameter send to web-service. * First thing I want to know, is how can I translate the table to xml code, since the following code is wrong, and I don't understand why : var i; var j; var myXML; var currRow; var currCell; var currControl; var newnode; var newText; var currControlLen; myXML = new ActiveXObject("Microsoft.XMLD...

Deserializing with XmlSerializer and XML namespaces
I'm using SQLXML to get XML documents from a SQL Server database and deserializing the results with an XmlSerialier. It was working perfectly until I started getting namespace prefixes in some of my elements (due to using import directives in the mapping schemas). Here's a relevant XML fragment-- the element wit the y0: namespace prefix does not deserialize. How can I make the deserializer correctly deserialize this element (which is nested within an XmlArray-attributed collection)? <UserList> <User ID="157" FirstName="Joe" LastName="Someone" Em...

Safe Multi User xml updates [best Practices??]
Hello, Im wondering, what's the best method to allow multpiple users to update an xml file at once. In my case, generally no user should be editing the same piece of data at any given time however there may be ten+ users updating the same xml file at once. The file has grown to somewhere along the lines of 3 MB, but shouldnt get much larger. im afraid that using xmldocument is beginning to become a costly process with such a large object being cahed and written so many times As an example this function uses a stream but leaves the file open for write procedures as it opens, which...

Sending a XML document via HTTP
I'm new to XML. I need to have my asp.net page accept an XML document sent via HTTP (from a Java app), process some info and send back a response as XML. I continue to get back an error on my web page: The data at the root level is invalid. Line 1, position 1. Currently, I am running the XML document through the class XmlDocument (so I can read the the line <?xml version="1.0" encoding="UTF-8">), saving it to a file on my server then opening it with XmlTextReader to read and process some info, and then responding back with XML. Thanks in advance. I'...

Client Script XML XPath problem
I am using client script to handle some XML stuff with MS XMLDOM But I ran into a problem in selecting the elements using selectNodes method The XML looks like: <root> ........................ <Table> <PK>3</cls_PK> <Person_Id>1</cls_LampType_FK> <ClassName>MV-175</cls_ClassName> <Department_Id>1</cls_LightType_FK> </Table> .................... </root> and here is the javascript code: var strNodeSelectionString = "Table[Department_Id = 1 and Person_Id = 1 ]"; var oClassNodesList = xDocClass.documentEl...

How to start working with XML in Excel?
(Windows XP Pro, Office 2003) I work with a Java-based program that creates an XML file. Sometimes information needs to be transferred between XML docs. At the moment, I can open an XML in Word, and copy and paste between the XMLs. Some of the data, though, would lend itself very well to an Excel spreadsheet. When I try to open an XML file with Excel (either by right-clck on the XML file and Open With or XL >> Data >> XML >> Import), Excel creates a schema that doesn't present the information in a way I can logically work with it. The Java program consists of forms ...

Validating an XML file with an external schema
Hi; If I have an xml file and a schema file and I want to validate that the xml file matches the schema - is this the best way? (This code works, I just want to make sure I am doing this the best way.) XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation | XmlSchemaValidationFlags.ReportValidationWarnings; XmlSchemaSet sc = new XmlSchemaSet(); sc.Add(null, schemaUrl); settings.Schemas = sc; reader = XmlReader.Create(url, settings); while (reader.Read()) ; -- tha...

integration manager
I'm trying to access a section of a source XML file (exported from Perfect Commerce) from a field script in an Integration Manager mapping. The ContactValue field is repeated several times and I can only access the first instance using the path SourceFields("ContactList.ContactInfo.ContactValue") Is it possible to use the SourceFields object to get to the email and fax instances of the ContactInfo field? Is there some other way? <ContactList> <ContactInfo> <ContactValue>555-555-5555</ContactValue> <ContactType>phone</C...

Problem with XML-Validation
I have got an XML file, that aderes to a XDR-Schema which references elements and attributes in two other XDR-Schemas. I want to validate this XML file before I create a DOM tree in C#. This works fine for every namespace except of the default namespace. In the default namespace there is no Event when the XML file is wrong. Could anybody tell me what there is wrong with my code (as seen below)? I have tried several things, but I could not make the validation work properly. The class simply creates a DOM form a XML file and writes every error out in the console. Best regards, Daniel Haag pu...

Validating XML in a WebMethod parameter
Hi, I've set up a SoapExtension class and XSD schema in order to validate the parameters of a webservice method call. However, I'm having a problem with one of the parameters - it's a string which accepts an XML fragment and I can't get it to validate using the schema. I need to go back to basics with this I think - can anyone point me to examples/articles of this technique? i.e. How do I define a webmethod parameter in the XSD schema that will validate an XML fragment? It's very simple XML too :-) e.g. <nodea> <nodeb id="..." /> <nodeb i...

XML for non-Web developers
First of all, I don't know anything about XML. I develop software for Windows platforms, but not web applications. What I want is to find out what XML has to offer for me. All the books and other resources I've encountered deal with XML in web applications. Are there books or resources that concentrate on other uses for XML? Thanks, -- Rubio Hey Rubio, I'd recommend buying XML pocket consultant, William Stanek, Microsoft Press ISBN 0-7356-1183-1. If you don't know much about XML it's a good book to get started on, and it's relatively cheap. XML is not just for web a...

Xml Text Reader and Writer Conditional?
I have an XML document like this <full> <doc> <a id="123">look</c> <b/> <c/> </doc> </full> loaded into a string that I read with an XmlTextReader. I want to write the contents with an XmlTextWriter to a new document. Every time the reader comes into contact with a "A" element, I want to send the attribute and element value to another method that returns a string which I will append after "c" for the writer. So I will have two documents, the original one and one with stuff after "c". ...

getting the xml from XmlTextWriter
We have an app that uses the XmlTextWriter to write XML to the local disk. It works and it's great. Now they want to write it to the database instead. Is there a way that I can just get the XML out of the XmlTextWriter? I looked at the XmlTextWriter class and can't seem to figure out how to take the XML out of it. I want to do this dim x as string x = XmlTextWriter.XML Thanks in advance, Rob * SneakyMonki wrote in microsoft.public.dotnet.xml: >We have an app that uses the XmlTextWriter to write XML to the local disk. It >works and it's great. Now they want to write i...

Fast XML Document Parsing? #2
I currently parse an xml document using the XmlTestReader class. The xml doc contains several records, each of which contains about 10 elements. I then convert each element in a record into its equivalent C# data type (e.g. for float values, I use float.Parse(elementVal) ) I then perform calculations using each of these converted values before overwriting the values when the next xml record is parsed. Is this the best technique? <rec> <val1> <val2> <val3> </rec> <rec> <val1> <val2> <val3> </rec> ...

Word documents that save in XML format
I use Office 2007 and for some reason all of my documents are saving into XML format (which I hate) and I cannot save them in Word format, and I cannot convert them into Word format. I have used Office 2007 every since it came out and have use office for many years. My OS is Windows 7 - Home Preimum upgrade from Vista. Can anyone please help me with settings that will allow me to save all of my documents in Word format and how I can convert XML documents back to Word format. I really hate XML, not sure how it go on my computer, but am guessing it may of had something to do ...

XML data in Excel
Version: 2004 Operating System: Mac OS X 10.4 (Tiger) Processor: Intel Is it possible to open XML data files in Excel for Mac? <br><br>I have several kml files that have sites with names and, latitude and longitude numbers for each. I would like to have this listing in excel. However, when I try to open the file as an xml file in Excel I get this message <br><br>The file you are trying to open is not a valid Excel XML Spreadsheet. <br><br>You can open the file as text in Excel. <br><br>I know this is true, however, I am expecting it to crea...

Locking XML file
Hi!! I have a web service that writes a node in xml file and saves it and closes it. Now it is a possiblitity that several users try to edit the same file at the same time. Is it possible to lock this xml file till the first user closes it and then release it for the next user. My function that writes xml file is as follows: Public Function AddNodetoAreaXML(ByVal TeamId As String, ByVal TeamName As String) As Boolean Dim xDoc As New XmlDocument Dim DocName As String = ConfigurationSettings.AppSettings("TeamXml") Try xDoc.Load(Do...

Dataset and XML
Hi I have an SQL Server stored procedure wich returns ceratin data and I have it in a Dataset. I am supposed to change that data into an specific standard XML format and write it to file. I am using Visual Studio 2005 wich is completely new to me. Could you help with some hints about how can I do that. I have been looking a lot about this from the Net but every thing I have found is very simple: GetXml() But that is not enough for me. I need to change that XML so that I get it in the previously defined standard format Thanks for any help Gabriel Hi Sorry for cross posting. I posted this a...

XML ContentType
Hi, I have the code to do webrequest for posting xml data. But I need to change the content type to objRequest.ContentType = "text/html; charset=iso-8859-1" Anybody have a sample which part of these code below I should change ? Dim strXml As String = "XML_DATA=" strXml = strXml + xmlDoc.OuterXml Dim sURL = http://www.domain.com Dim buffer As Byte() = System.Text.Encoding.UTF8.GetBytes(strXml.ToString()) Dim objRequest As WebRequest = WebRequest.Create(sURL) objRequest.Method = "POST" objRequest.ContentType = "application/x-www-form-urlencoded" myWrit...