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

problem adding data to XML doc compliant with XSD

Hi all,

I am new to .NET and the way XML data is handled in .NET

I wrote a small application with .NET forms in C++
The application reads data from an XML file to fill-in
the fields of the form. This works fine but when I try to add
new data to the XML file it does not comply with the XML schema
file I am using.

Here some xml and code snipplets:

Schema description:

<xs:element name="Store" type="StoreType" />
<xs:complexType name="StoreType">
<xs:sequence maxOccurs="unbounded">
<xs:element name="Config" type="ConfigurationType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ConfigurationType">
<xs:sequence>
... simple elements of type "string" and "long" ...
</xs:sequence>
<xs:attribute name="configName" type="xs:string" />
</xs:complexType>

An xml file made with this schema manually:

<Store xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tempuri.org/XMLSchema.xsd&#xD;&#xA;Config.xsd">
<Config configName="TestA">
<FileName>C:/temp/keineAhnungX.mpg</FileName>
...
</Config>
</Store>

After adding a new config element in the .NET application the XML output
looks like this:

<NewDataSet xmlns="http://tempuri.org/XMLSchema.xsd">
<Store>
<Config configName="TestA">
<FileName>C:/temp/keineAhnungX.mpg</FileName>
...
</Config>
</Store>
<Config configName="TestD">
<FileName>TestFile</FileName>
</Config>
</NewDataSet>

I have now a new Element which does not exist in the schema "NewDataSet"
and the added config element is not a sub element of the Store element.
This is very confusing or shall I say disappointing.

<code>

// Here is the way I am dealing with the xml data
// This uses the xml Schema description which is first one in my post
this->xmlData = new XmlDataDocument();
this->xmlData->DataSet->ReadXmlSchema("Config.xsd");

// reading the xsd compliant xml data
XmlTextReader* reader = new XmlTextReader("Daten.xml");
reader->MoveToContent(); // Moves the reader to the root node.
this->xmlData->Load(reader);

// now I get two DataTable, one is the Store table containing all
// store elements
// but I am interested in the other one, the Config table
DataTableCollection* myTableCollection = xmlData->DataSet->Tables;

// I am using the "Config" DataTable to append a new element behind the
// last config element.

DataRow* newData = this->configTable->NewRow();
newData->set_Item(S"configName", S"TestD");
newData->set_Item(S"FileName", S"TestFile");

this->configTable->Rows->Add(newData);

// now I am writing the XML back to disc resulting in an unusable
// non-complying data file

XmlTextWriter* xmlWriter =
new XmlTextWriter("test.xml", System::Text::Encoding::UTF8);
xmlWriter->Formatting = Formatting::Indented;

this->xmlData->Write(xmlWriter);
xmlWriter->Close();

</code>

What is wrong in the way I am using the XML framework of .NET?

TIA
Michael
Nov 12 '05 #1
0 1065

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

Similar topics

2
by: Brian Idzik | last post by:
I've successfully setup a xhtml 1.0 strict page with Mozilla & Netscape to display links in a toolbar into an internal <div id='content'> within the same document. The toolbar uses some...
6
by: Thomas | last post by:
Hi, I'm having a problem with the dynamically created inputfields in Internet Explorer. The situation is the following: - I have a dynamically created table with a textbox in each Cell. - It...
31
by: muralipmanohar | last post by:
Hello all , I need a help on this code kindly help me out for the below code I worked on the Turboc the result I was expecting was different from what has been printed I have indicated the line...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
20
by: barbara | last post by:
Hi, all I have to read a binary data which is four bytes and I need to use the following function to deal with data: Private Function BIT(ByVal Val As UInt32, ByVal BitNum As UInt32) As...
3
by: f1racing24 | last post by:
I am trying to compile this class in the command-line and this error comes up 'Start -> C:\Inetpub\wwwroot\DCReview_Brinkster\code>vbc /t:library /verbose...
2
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I...
4
by: andreas.fabri | last post by:
I have a problem reading integers separated by commas with VC8 This program: ___________________________ // read.C #include <iostream> int main()
3
by: Ralph | last post by:
Hi I have small function to generate my form controls: function buildInput(sType, vValue, vId, sName, sLabel){ var oInput = null; var oLabel = document.createElement('label'); var oCont =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.