I am creating a xml file parsing a PB .srd file.
It is executing properly but the error is "MISSING ROOT
ELEMENT"
the code is:
sring[] dw_parts=null;
FileStream fs = File.Open("C:\\ Documents and
Settings\\santh oshi\\Desktop\\ dw_grid_qaddres s.txt",FileMod
e.Open,FileAcce ss.Read);
StreamReader sr = new StreamReader(fs );
StringReader rd = new StringReader(sr .ReadToEnd());
XmlTextWriter XMLWriter = new XmlTextWriter
("d:\\santhoshi \\projects\\cur rent\\xmlwriter .xml",System.T
ext.Encoding.Un icode);
try
{
for(string line=rd.ReadLin e();line!=null; line=rd.ReadLin e
())
{
if(Regex.IsMatc h(
line , "datawindow",Re gexOptions.Igno reCase))
{
dw_parts=Regex. Split(line,@"\s +|\s*=\s*|\s*\)
\s*|\s*\(\s*");
for(int i=0;i<dw_parts. Length;i++)
{
//XMLWriter.Write String("<?xml
version="+'"'+" 1.0"+'"'+"?>") ;
if
(Regex.IsMatch( dw_parts[i],"datawindow "))
{
XMLWriter.Forma tting = Formatting.Inde nted;
XMLWriter.Write StartDocument() ;
XMLWriter.Write StartElement(dw _parts[i]);
//XMLWriter.Write StartElement(dw _parts[i]);
}
else if(Regex.IsMatc h(dw_parts[i],"units"))
{
XMLWriter.Write StartElement("u nits",dw_parts[i++]);
}
}
XMLWriter.Write EndElement();
//XMLWriter.Write EndElement();
}
//
XmlDocument doc = new XmlDocument();
//
doc.Load
("d:\\santhoshi \\projects\\cur rent\\xmlwriter .xml");
}
}
catch(Exception X)
{
MessageBox.Show (X.Message);
}
}
For each match it should create a element or node with the
contents .
I am new to XML coding in C# can u please help me out
It is executing properly but the error is "MISSING ROOT
ELEMENT"
the code is:
sring[] dw_parts=null;
FileStream fs = File.Open("C:\\ Documents and
Settings\\santh oshi\\Desktop\\ dw_grid_qaddres s.txt",FileMod
e.Open,FileAcce ss.Read);
StreamReader sr = new StreamReader(fs );
StringReader rd = new StringReader(sr .ReadToEnd());
XmlTextWriter XMLWriter = new XmlTextWriter
("d:\\santhoshi \\projects\\cur rent\\xmlwriter .xml",System.T
ext.Encoding.Un icode);
try
{
for(string line=rd.ReadLin e();line!=null; line=rd.ReadLin e
())
{
if(Regex.IsMatc h(
line , "datawindow",Re gexOptions.Igno reCase))
{
dw_parts=Regex. Split(line,@"\s +|\s*=\s*|\s*\)
\s*|\s*\(\s*");
for(int i=0;i<dw_parts. Length;i++)
{
//XMLWriter.Write String("<?xml
version="+'"'+" 1.0"+'"'+"?>") ;
if
(Regex.IsMatch( dw_parts[i],"datawindow "))
{
XMLWriter.Forma tting = Formatting.Inde nted;
XMLWriter.Write StartDocument() ;
XMLWriter.Write StartElement(dw _parts[i]);
//XMLWriter.Write StartElement(dw _parts[i]);
}
else if(Regex.IsMatc h(dw_parts[i],"units"))
{
XMLWriter.Write StartElement("u nits",dw_parts[i++]);
}
}
XMLWriter.Write EndElement();
//XMLWriter.Write EndElement();
}
//
XmlDocument doc = new XmlDocument();
//
doc.Load
("d:\\santhoshi \\projects\\cur rent\\xmlwriter .xml");
}
}
catch(Exception X)
{
MessageBox.Show (X.Message);
}
}
For each match it should create a element or node with the
contents .
I am new to XML coding in C# can u please help me out