P
PZWU
How can I build a big XML file by appending a few smaller
xml files in C#?
Below is what I've been trying:
/* FileString.xml is the path and name string of the big
xml file*/
XmlTextWriter writer = new XmlTextWriter (FileString,
System.Text.Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("FundXML");
/*p_FundOperationFileName is the string name of a smaller
xml file saved under d:\\xml\\FundOperationXML directory */
string Text = AppendXMLFile
(p_FundOperationFileName, "d:\\xml\\FundOperationXML");
writer.WriteString(Text);
writer.WriteEndElement();
writer.Flush();
writer.Close();
in function AppendXMLFile:
string strfile = path +"\\"+filename;
string s = "?>";
try
{
StreamReader sr = new StreamReader(strfile);
String line;
/*while loop removes <?xml version="1.0" encoding="utf-8" ?
while ((line = sr.ReadLine()) != null)
{
int idx = line.IndexOf(s);
sr.Close();
return line.Substring(idx+2);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
The big XML constructed this way is not "well formed" if
open it in xmlspy and xslt couldn't retrieve info from it
if it's loaded as xslt source xml file.
Please help and thanks in advance.
xml files in C#?
Below is what I've been trying:
/* FileString.xml is the path and name string of the big
xml file*/
XmlTextWriter writer = new XmlTextWriter (FileString,
System.Text.Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("FundXML");
/*p_FundOperationFileName is the string name of a smaller
xml file saved under d:\\xml\\FundOperationXML directory */
string Text = AppendXMLFile
(p_FundOperationFileName, "d:\\xml\\FundOperationXML");
writer.WriteString(Text);
writer.WriteEndElement();
writer.Flush();
writer.Close();
in function AppendXMLFile:
string strfile = path +"\\"+filename;
string s = "?>";
try
{
StreamReader sr = new StreamReader(strfile);
String line;
/*while loop removes <?xml version="1.0" encoding="utf-8" ?
to the big xml file*/from the xml file and return the rest as string append
while ((line = sr.ReadLine()) != null)
{
int idx = line.IndexOf(s);
sr.Close();
return line.Substring(idx+2);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
The big XML constructed this way is not "well formed" if
open it in xmlspy and xslt couldn't retrieve info from it
if it's loaded as xslt source xml file.
Please help and thanks in advance.