Click here to Skip to main content
15,888,320 members
Home / Discussions / C#
   

C#

 
GeneralRe: axMediaPlayer MouseLeave Event Pin
Christian Graus21-Sep-06 1:06
protectorChristian Graus21-Sep-06 1:06 
GeneralRe: axMediaPlayer MouseLeave Event Pin
mikone21-Sep-06 2:05
mikone21-Sep-06 2:05 
QuestionPInvoke Dll Pin
kulile20-Sep-06 23:19
kulile20-Sep-06 23:19 
AnswerRe: PInvoke Dll Pin
mav.northwind21-Sep-06 0:01
mav.northwind21-Sep-06 0:01 
Questiondatagrid view scroll Pin
faladrim20-Sep-06 23:02
faladrim20-Sep-06 23:02 
AnswerRe: datagrid view scroll Pin
Robert Rohde20-Sep-06 23:34
Robert Rohde20-Sep-06 23:34 
GeneralRe: datagrid view scroll Pin
faladrim20-Sep-06 23:37
faladrim20-Sep-06 23:37 
QuestionXML errors when reading in C# Pin
bigove20-Sep-06 22:33
bigove20-Sep-06 22:33 
Hello,

I am trying to read an XML file and break it up into smaller chunks but am having real problems in doing so as I have never used XML before.

I wish to read a large XML document and cycle through it, copying each record to a new file that I have created (with the relevant header info), until I have 1000 records, then start again. The format of the records is:

<Record>
<attribute1>blah blah</attribute1>
<attribute2>blah blah</attribute2>
<attribute3>blah blah</attribute3>
</Record>

So far I have created the following code:

while (fileReader != null)
{
// Create a file to write to
XmlTextWriter fileWriter = new XmlTextWriter(directory + "\\Output" + x + " myXMLfile.xml", System.Text.Encoding.GetEncoding("ISO-8859-1"));//null);
//fileWriter.WriteStartDocument();

// Write the header details to the new file
fileWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='ISO-8859-1'");
fileWriter.WriteComment("Some commentd");
fileWriter.WriteStartElement("message");
fileWriter.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
fileWriter.WriteAttributeString("xsi", "noNamespaceSchemaLocation", null, "myXSD.xsd");

// Add 'messageHeader' as part of the header
while (fileReader.Name != "messageHeader")
{
fileReader.Read();
}
fileWriter.WriteNode(fileReader, true);

// Write each row to the file, until 1000 records have been written
for (int i = 1; i <= 1001; i++)
{
while (fileReader.Name != "CISKASNRecord")
fileReader.Read();

fileWriter.WriteNode(fileReader, true);
fileWriter.Flush();
}

// Tidy up and close the file so that a new one can be opened
fileWriter.WriteEndElement();
fileWriter.Close();
x++;
}

I can create a new XML file which prints the header info, then begins to cycle through and print the records as expected (hoped!). However, it crashes at the second document with the following error:

"XML document must have a top level element."Error processing resource 'file:///C:/........"

If I increase the size of my for-loop to include all records to see what happens it crashes at the end of the file with the following error:

"The following tags were not closed: message"

I guess this may be the real reason for my errors, however the C# code looks to close all tags so I can't see how this error is appearing? Can anybody help here please?

AnswerRe: XML errors when reading in C# [modified] Pin
Christian Graus20-Sep-06 23:43
protectorChristian Graus20-Sep-06 23:43 
GeneralRe: XML errors when reading in C# Pin
bigove20-Sep-06 23:49
bigove20-Sep-06 23:49 
GeneralRe: XML errors when reading in C# Pin
Christian Graus21-Sep-06 0:09
protectorChristian Graus21-Sep-06 0:09 
GeneralRe: XML errors when reading in C# Pin
bigove21-Sep-06 0:33
bigove21-Sep-06 0:33 
GeneralRe: XML errors when reading in C# Pin
Christian Graus21-Sep-06 0:37
protectorChristian Graus21-Sep-06 0:37 
GeneralRe: XML errors when reading in C# Pin
bigove21-Sep-06 0:42
bigove21-Sep-06 0:42 
GeneralRe: XML errors when reading in C# Pin
bigove21-Sep-06 0:52
bigove21-Sep-06 0:52 
Questionprogress bar Pin
Parshant Verma20-Sep-06 21:53
Parshant Verma20-Sep-06 21:53 
AnswerRe: progress bar Pin
Christian Graus20-Sep-06 21:55
protectorChristian Graus20-Sep-06 21:55 
AnswerRe: progress bar Pin
Waqas Nasir20-Sep-06 22:06
Waqas Nasir20-Sep-06 22:06 
QuestiontoolStripProgressBar &amp;amp;amp; SQL [modified] Pin
shopi3020-Sep-06 21:50
shopi3020-Sep-06 21:50 
AnswerRe: toolStripProgressBar &amp; SQL Pin
Christian Graus20-Sep-06 21:57
protectorChristian Graus20-Sep-06 21:57 
Questionhow to check if a string is a letter or a number Pin
faladrim20-Sep-06 21:45
faladrim20-Sep-06 21:45 
AnswerRe: how to check if a string is a letter or a number Pin
Christian Graus20-Sep-06 21:54
protectorChristian Graus20-Sep-06 21:54 
AnswerRe: how to check if a string is a letter or a number Pin
Guffa20-Sep-06 21:54
Guffa20-Sep-06 21:54 
GeneralRe: how to check if a string is a letter or a number Pin
faladrim20-Sep-06 22:59
faladrim20-Sep-06 22:59 
AnswerRe: how to check if a string is a letter or a number Pin
Guffa21-Sep-06 6:22
Guffa21-Sep-06 6:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.