本文整理汇总了C#中System.Xml.XmlDocument.InsertAfter方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.InsertAfter方法的具体用法?C# XmlDocument.InsertAfter怎么用?C# XmlDocument.InsertAfter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.InsertAfter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeXml
//ArrayList openElements = new ArrayList();
public void SerializeXml(IList<StarSystem> starSystems)
{
MemoryStream memXmlStream = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(starSystems.GetType(), null, new Type[] { typeof(Planet), typeof(StarSystem) }, new XmlRootAttribute("Stars"), null, null);
serializer.Serialize(memXmlStream, starSystems);
XmlDocument xmlDoc = new XmlDocument();
memXmlStream.Seek(0, SeekOrigin.Begin);
xmlDoc.Load(memXmlStream);
XmlProcessingInstruction newPI;
String PItext = string.Format("type='text/xsl' href='{0}'", "system.xslt");
newPI = xmlDoc.CreateProcessingInstruction("xml-stylesheet", PItext);
xmlDoc.InsertAfter(newPI, xmlDoc.FirstChild);
// Now write the document
// out to the final output stream
XmlTextWriter wr = new XmlTextWriter("system.xml", System.Text.Encoding.ASCII);
wr.Formatting = Formatting.Indented;
wr.IndentChar = '\t';
wr.Indentation = 1;
XmlWriterSettings settings = new XmlWriterSettings();
XmlWriter writer = XmlWriter.Create(wr, settings);
xmlDoc.WriteTo(writer);
writer.Flush();
//Console.Write(xmlDoc.InnerXml);
}
示例2: Init
private void Init(string rootName)
{
try
{
doc = new XmlDocument();
var dec = doc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
doc.InsertAfter(dec, null);
root = doc.CreateNode(XmlNodeType.Element, rootName, "");
doc.InsertAfter(root, dec);
}
catch { }
}
示例3: FormatXml
/// <summary>
/// Formats the provided XML so it's indented and humanly-readable.
/// </summary>
/// <param name="inputXml">The input XML to format.</param>
/// <returns></returns>
public static string FormatXml(XmlElement element)
{
XmlDocument document = new XmlDocument();
var node = document.ImportNode(element, true);
document.InsertAfter(node, null);
StringBuilder builder = new StringBuilder();
var xmlSettings = new XmlWriterSettings
{
Indent = true,
IndentChars = @" ",
NewLineChars = Environment.NewLine,
NewLineHandling = NewLineHandling.Replace,
OmitXmlDeclaration = true,
Encoding = Encoding.UTF8,
};
using (var writer = XmlWriter.Create(builder, xmlSettings))
{
document.Save(writer);
}
return builder.ToString();
}
示例4: Save3DPoints
private void Save3DPoints(Stream file, string path)
{
XmlDocument dataDoc = new XmlDocument();
var rootNode = dataDoc.CreateElement("Points");
for(int i= 0; i < _points3D.Count; ++i)
{
var point3D = _points3D[i];
var pointImg = _left[i];
var pointNode = dataDoc.CreateElement("Point");
var attRealX = dataDoc.CreateAttribute("realx");
attRealX.Value = point3D.At(0).ToString();
var attRealY = dataDoc.CreateAttribute("realy");
attRealY.Value = point3D.At(1).ToString();
var attRealZ = dataDoc.CreateAttribute("realz");
attRealZ.Value = point3D.At(2).ToString();
var attImgX = dataDoc.CreateAttribute("imgx");
attImgX.Value = pointImg.At(0).ToString();
var attImgY = dataDoc.CreateAttribute("imgy");
attImgY.Value = pointImg.At(1).ToString();
pointNode.Attributes.Append(attRealX);
pointNode.Attributes.Append(attRealY);
pointNode.Attributes.Append(attRealZ);
pointNode.Attributes.Append(attImgX);
pointNode.Attributes.Append(attImgY);
rootNode.AppendChild(pointNode);
}
dataDoc.InsertAfter(rootNode, dataDoc.DocumentElement);
dataDoc.Save(file);
}
示例5: SaveDictToXML
public void SaveDictToXML(String xmlFileName)
{
XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(docNode);
XmlWhitespace xml_declaration_newLine = doc.CreateWhitespace("\r\n");
doc.InsertAfter(xml_declaration_newLine, docNode);
XmlNode tourNode = doc.CreateElement("TourStoryboard");
XmlAttribute tourNode_displayName = doc.CreateAttribute("displayName");
XmlAttribute tourNode_description = doc.CreateAttribute("description");
//// duratoin experiment
XmlAttribute tourNode_duration = doc.CreateAttribute("duration");
tourNode_duration.Value = tourStoryboard.totalDuration.ToString();
tourNode.Attributes.Append(tourNode_duration);
tourNode_displayName.Value = tourStoryboard.displayName;
tourNode_description.Value = tourStoryboard.description;
tourNode.Attributes.Append(tourNode_displayName);
tourNode.Attributes.Append(tourNode_description);
doc.AppendChild(tourNode);
foreach (Timeline tl in tourBiDictionary.firstKeys)
{
TourTL tourTL = (TourTL)tl;
BiDictionary<double, TourEvent> tourTL_dict = tourBiDictionary[tl][0];
if ((tourTL.type == TourTLType.artwork) || (tourTL.type == TourTLType.media) || tourTL.type == TourTLType.highlight || tourTL.type == TourTLType.path)
{
XmlNode TLNode = doc.CreateElement("TourParallelTL");
XmlAttribute TLNode_type = doc.CreateAttribute("type");
XmlAttribute TLNode_displayName = doc.CreateAttribute("displayName");
XmlAttribute TLNode_file = doc.CreateAttribute("file");
TLNode_type.Value = tourTL.type.ToString();
TLNode_displayName.Value = tourTL.displayName;
TLNode_file.Value = tourTL.file;
TLNode.Attributes.Append(TLNode_type);
TLNode.Attributes.Append(TLNode_displayName);
TLNode.Attributes.Append(TLNode_file);
tourNode.AppendChild(TLNode);
foreach (double beginTime in tourTL_dict.firstKeys)
{
TourEvent tourEvent = tourTL_dict[beginTime][0];
if (tourEvent.type == TourEvent.Type.zoomMSI)
{
ZoomMSIEvent zoomMSIEvent = (ZoomMSIEvent)tourEvent;
XmlNode TourEventNode = doc.CreateElement("TourEvent");
XmlAttribute TourEventNode_beginTime = doc.CreateAttribute("beginTime");
XmlAttribute TourEventNode_type = doc.CreateAttribute("type");
XmlAttribute TourEventNode_scale = doc.CreateAttribute("scale");
XmlAttribute TourEventNode_toMSIPointX = doc.CreateAttribute("toMSIPointX");
XmlAttribute TourEventNode_toMSIPointY = doc.CreateAttribute("toMSIPointY");
XmlAttribute TourEventNode_duration = doc.CreateAttribute("duration");
TourEventNode_beginTime.Value = beginTime.ToString();
TourEventNode_type.Value = "ZoomMSIEvent";
TourEventNode_scale.Value = zoomMSIEvent.absoluteScale.ToString();
TourEventNode_toMSIPointX.Value = zoomMSIEvent.zoomToMSIPointX.ToString();
TourEventNode_toMSIPointY.Value = zoomMSIEvent.zoomToMSIPointY.ToString();
TourEventNode_duration.Value = zoomMSIEvent.duration.ToString();
TourEventNode.Attributes.Append(TourEventNode_beginTime);
TourEventNode.Attributes.Append(TourEventNode_type);
TourEventNode.Attributes.Append(TourEventNode_scale);
TourEventNode.Attributes.Append(TourEventNode_toMSIPointX);
TourEventNode.Attributes.Append(TourEventNode_toMSIPointY);
TourEventNode.Attributes.Append(TourEventNode_duration);
TLNode.AppendChild(TourEventNode);
}
else if (tourEvent.type == TourEvent.Type.fadeInMedia)
{
FadeInMediaEvent fadeInMediaEvent = (FadeInMediaEvent)tourEvent;
XmlNode TourEventNode = doc.CreateElement("TourEvent");
XmlAttribute TourEventNode_beginTime = doc.CreateAttribute("beginTime");
XmlAttribute TourEventNode_type = doc.CreateAttribute("type");
XmlAttribute TourEventNode_toScreenPointX = doc.CreateAttribute("toScreenPointX");
XmlAttribute TourEventNode_toScreenPointY = doc.CreateAttribute("toScreenPointY");
XmlAttribute TourEventNode_scale = doc.CreateAttribute("scale");
XmlAttribute TourEventNode_duration = doc.CreateAttribute("duration");
TourEventNode_beginTime.Value = beginTime.ToString();
TourEventNode_type.Value = "FadeInMediaEvent";
TourEventNode_toScreenPointX.Value = fadeInMediaEvent.fadeInMediaToScreenPointX.ToString();
TourEventNode_toScreenPointY.Value = fadeInMediaEvent.fadeInMediaToScreenPointY.ToString();
TourEventNode_scale.Value = fadeInMediaEvent.absoluteScale.ToString();
TourEventNode_duration.Value = fadeInMediaEvent.duration.ToString();
TourEventNode.Attributes.Append(TourEventNode_beginTime);
TourEventNode.Attributes.Append(TourEventNode_type);
TourEventNode.Attributes.Append(TourEventNode_toScreenPointX);
TourEventNode.Attributes.Append(TourEventNode_toScreenPointY);
TourEventNode.Attributes.Append(TourEventNode_scale);
TourEventNode.Attributes.Append(TourEventNode_duration);
TLNode.AppendChild(TourEventNode);
}
else if (tourEvent.type == TourEvent.Type.fadeOutMedia)
//.........这里部分代码省略.........
示例6: SaveCalibMatched
public void SaveCalibMatched(Stream file, string path)
{
XmlDocument dataDoc = new XmlDocument();
var rootNode = dataDoc.CreateElement("Points");
var calibMatchedLeft = new List<CalibrationPoint>(CalibrationPointsLeft.Count);
var calibMatchedRight = new List<CalibrationPoint>(CalibrationPointsRight.Count);
for(int i = 0; i < CalibrationPointsLeft.Count; ++i)
{
var cleft = CalibrationPointsLeft[i];
var cright = CalibrationPointsRight.Find((cp) =>
{
return cp.GridNum == cleft.GridNum &&
cp.RealCol == cleft.RealCol &&
cp.RealRow == cleft.RealRow;
});
if(cright != null)
{
calibMatchedLeft.Add(cleft);
calibMatchedRight.Add(cright);
}
}
for(int i = 0; i < calibMatchedLeft.Count; ++i)
{
var cpL = calibMatchedLeft[i];
var cpR = calibMatchedRight[i];
var pointNode = dataDoc.CreateElement("Point");
var attImgX = dataDoc.CreateAttribute("imgx");
attImgX.Value = cpL.ImgX.ToString("F3");
var attImgY = dataDoc.CreateAttribute("imgy");
attImgY.Value = cpL.ImgY.ToString("F3");
var attImgX2 = dataDoc.CreateAttribute("imgx2");
attImgX2.Value = cpR.ImgX.ToString("F3");
var attImgY2 = dataDoc.CreateAttribute("imgy2");
attImgY2.Value = cpR.ImgY.ToString("F3");
pointNode.Attributes.Append(attImgX);
pointNode.Attributes.Append(attImgY);
pointNode.Attributes.Append(attImgX2);
pointNode.Attributes.Append(attImgY2);
rootNode.AppendChild(pointNode);
}
dataDoc.InsertAfter(rootNode, dataDoc.DocumentElement);
dataDoc.Save(file);
}
示例7: InsertAfter
public void InsertAfter()
{
document = new XmlDocument();
document.LoadXml("<root><sub1 /><sub2 /></root>");
XmlElement docelem = document.DocumentElement;
XmlElement newelem = document.CreateElement("good_child");
docelem.InsertAfter(newelem, docelem.FirstChild);
AssertEquals("InsertAfter.Normal", 3, docelem.ChildNodes.Count);
AssertEquals("InsertAfter.First", "sub1", docelem.FirstChild.Name);
AssertEquals("InsertAfter.Last", "sub2", docelem.LastChild.Name);
AssertEquals("InsertAfter.Prev", "good_child", docelem.FirstChild.NextSibling.Name);
AssertEquals("InsertAfter.Next", "good_child", docelem.LastChild.PreviousSibling.Name);
// this doesn't throw any exception *only on .NET 1.1*
// .NET 1.0 throws an exception.
try {
document.InsertAfter(document.CreateElement("BAD_MAN"), docelem);
#if USE_VERSION_1_1
AssertEquals("InsertAfter with bad location",
"<root><sub1 /><good_child /><sub2 /></root><BAD_MAN />",
document.InnerXml);
} catch (XmlException ex) {
throw ex;
}
#else
} catch (Exception) {}
示例8: SaveToFile
public void SaveToFile(Stream file, string path)
{
XmlDocument dataDoc = new XmlDocument();
var rootNode = dataDoc.CreateElement("Points");
foreach(var cpoint in _pointList)
{
var pointNode = dataDoc.CreateElement("Point");
var attImgX = dataDoc.CreateAttribute("imgx");
attImgX.Value = cpoint.ImgX.ToString("F3");
var attImgY = dataDoc.CreateAttribute("imgy");
attImgY.Value = cpoint.ImgY.ToString("F3");
var attGridNum = dataDoc.CreateAttribute("grid");
attGridNum.Value = cpoint.GridNum.ToString();
var attRow = dataDoc.CreateAttribute("gridRow");
attRow.Value = cpoint.RealRow.ToString();
var attCol = dataDoc.CreateAttribute("gridColumn");
attCol.Value = cpoint.RealCol.ToString();
var attRealX = dataDoc.CreateAttribute("realx");
attRealX.Value = cpoint.RealX.ToString("F3");
var attRealY = dataDoc.CreateAttribute("realy");
attRealY.Value = cpoint.RealY.ToString("F3");
var attRealZ = dataDoc.CreateAttribute("realz");
attRealZ.Value = cpoint.RealZ.ToString("F3");
pointNode.Attributes.Append(attImgX);
pointNode.Attributes.Append(attImgY);
pointNode.Attributes.Append(attGridNum);
pointNode.Attributes.Append(attRow);
pointNode.Attributes.Append(attCol);
pointNode.Attributes.Append(attRealX);
pointNode.Attributes.Append(attRealY);
pointNode.Attributes.Append(attRealZ);
rootNode.AppendChild(pointNode);
}
dataDoc.InsertAfter(rootNode, dataDoc.DocumentElement);
dataDoc.Save(file);
}
示例9: WriteSVGString
/// <summary>
/// Get a string that contains a complete SVG document. XML version, DOCTYPE etc are included.
/// </summary>
/// <returns></returns>
/// <param name="compressAttributes">Should usually be set true. Causes the XML output to be optimized so that
/// long attributes like styles and transformations are represented with entities.</param>
public string WriteSVGString(bool compressAttributes)
{
string s;
string ents = "";
XmlDocument doc = new XmlDocument();
var declaration = doc.CreateXmlDeclaration("1.0", null, "yes");
doc.AppendChild(declaration);
//write out our SVG tree to the new XmlDocument
WriteXmlElements(doc, null);
doc.DocumentElement.SetAttribute("xmlns", "http://www.w3.org/2000/svg");
if (compressAttributes)
ents = SvgFactory.CompressXML(doc, doc.DocumentElement);
doc.XmlResolver = new DummyXmlResolver();
doc.InsertAfter(
doc.CreateDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", ents),
declaration
);
//This complicated business of writing to a memory stream and then reading back out to a string
//is necessary in order to specify UTF8 -- for some reason the default is UTF16 (which makes most renderers
//give up)
MemoryStream ms = new MemoryStream();
XmlTextWriter wr = new XmlTextWriter(ms, new UTF8Encoding());
wr.Formatting = Formatting.None; // Indented formatting would be nice for debugging but causes unwanted trailing white spaces between <text> and <tspan> elements in Internet Explorer
doc.Save(wr);
byte[] buf = ms.ToArray();
s = Encoding.UTF8.GetString(buf, 0, buf.Length);
wr.Close();
return s;
}
示例10: addCheckSum
string addCheckSum(string xmlFileName, string chksum)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFileName);
XmlComment chkSumComment;
chkSumComment = xmlDoc.CreateComment("Checksum:" + chksum);
XmlElement root = xmlDoc.DocumentElement;
xmlDoc.InsertAfter(chkSumComment, root);
xmlDoc.Save(xmlFileName);
return chksum;
}
示例11: ReGenerateSchema
protected static void ReGenerateSchema(XmlDocument xmlDoc)
{
string dtd = DocumentType.GenerateXmlDocumentType();
// remove current doctype
XmlNode n = xmlDoc.FirstChild;
while (n.NodeType != XmlNodeType.DocumentType && n.NextSibling != null)
{
n = n.NextSibling;
}
if (n.NodeType == XmlNodeType.DocumentType)
{
xmlDoc.RemoveChild(n);
}
XmlDocumentType docType = xmlDoc.CreateDocumentType("root", null, null, dtd);
xmlDoc.InsertAfter(docType, xmlDoc.FirstChild);
}
示例12: UpdateProduct
public static string UpdateProduct(string product, string buildNumber, string edition)
{
var prodDoc = new XmlDocument{XmlResolver = null};
prodDoc.Load(product);
XmlProcessingInstruction lastOne = null;
bool foundBuildNumber = false;
bool foundEdition = false;
Debug.Assert(prodDoc.DocumentElement != null, "prodDoc.DocumentElement != null");
foreach (var childNode in prodDoc.ChildNodes.Cast<XmlNode>().Where(childNode => childNode.NodeType == XmlNodeType.ProcessingInstruction).Cast<XmlProcessingInstruction>())
{
if (childNode.Value.StartsWith("BUILD_NUMBER"))
{
childNode.Value = string.Format(@"BUILD_NUMBER=""{0}""", buildNumber);
foundBuildNumber = true;
}
else if (childNode.Value.StartsWith("Edition"))
{
childNode.Value = string.Format(@"Edition=""{0}""", edition);
foundEdition = true;
}
else
{
lastOne = childNode;
}
}
if (!foundBuildNumber)
{
var verProcInst = prodDoc.CreateProcessingInstruction("define",
string.Format(@"BUILD_NUMBER=""{0}""", buildNumber));
prodDoc.InsertAfter(verProcInst, lastOne);
}
if (!foundEdition)
{
var verProcInst = prodDoc.CreateProcessingInstruction("define",
string.Format(@"Edition=""{0}""", edition));
prodDoc.InsertAfter(verProcInst, lastOne);
}
var tempName = Path.GetTempFileName();
var writer = XmlWriter.Create(tempName, new XmlWriterSettings {Indent = true, Encoding = Encoding.UTF8});
prodDoc.Save(writer);
writer.Close();
return tempName;
}
示例13: SendQuestion
public XmlDocument SendQuestion(string sInput)
{
//kanoume to authentication gia to service
ServiceAuthHeaderValidation.Validate(CustomSoapHeader);
string username = null;
string password = null;
string prefix = null;
string NamspaceURI = null;
XmlDocument doc = new XmlDocument();
XmlDocument doc_out = new XmlDocument();
string con_string = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(con_string);
string con_string_trust = WebConfigurationManager.ConnectionStrings["TrustMainConnectionString"].ConnectionString;
SqlConnection con_trust = new SqlConnection(con_string_trust);
try
{
XmlDeclaration xmlindeclaration = null;
xmlindeclaration = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.InsertBefore(xmlindeclaration, doc.DocumentElement);
doc.LoadXml(sInput);
//diavazoume ta username password gia kathe customer
username = System.Configuration.ConfigurationManager.AppSettings["username"];
password = System.Configuration.ConfigurationManager.AppSettings["password"];
prefix = System.Configuration.ConfigurationManager.AppSettings["prefix"];
NamspaceURI = System.Configuration.ConfigurationManager.AppSettings["NamspaceURI"];
//FTIAXNOUME TO XML_EKSODOU
XmlDeclaration xmldeclaration = null;
xmldeclaration = doc_out.CreateXmlDeclaration("1.0", "utf-8", null);
doc_out.InsertBefore(xmldeclaration, doc_out.DocumentElement);
XmlAttribute attr1 = doc_out.CreateAttribute("xmlns:"+prefix);
attr1.Value = NamspaceURI;
XmlElement root_element = null;
root_element = doc_out.CreateElement(prefix, "EntityDetrimentalData", NamspaceURI);
doc_out.InsertAfter(root_element, xmldeclaration);
doc_out.DocumentElement.Attributes.Append(attr1);
//VRISKOUME TO PELATH POU KANEI TO ERWTHMA
SqlCommand cmd = null;
cmd = new SqlCommand("SELECT_CUSTOMER", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@CUSTOMER_USERNAME", username));
cmd.Parameters.Add(new SqlParameter("@CUSTOMER_PASSWORD", password));
SqlParameter ID_PARAM = new SqlParameter("@CUSTOMER_ID", 0);
ID_PARAM.Direction = ParameterDirection.Output;
ID_PARAM.SqlDbType = SqlDbType.Int;
cmd.Parameters.Add(ID_PARAM);
int CUSTOMER_ID = 0;
con.Open();
cmd.ExecuteNonQuery();
CUSTOMER_ID = (int)ID_PARAM.Value;
con.Close();
//AN VRETHEI O PELATHS DIAVAZOUME TA STOIXEIA TOU ERWTHMATOS
if (CUSTOMER_ID != 0)
{
XmlNodeList list = doc.SelectNodes("//XML/PERSONCOMPANIES");
string output = "";
foreach (XmlNode NODE in list)
{
con.Open();
XmlDocument doc1 = new XmlDocument();
doc1.LoadXml(NODE.InnerXml);
int QUESTION_ID = 0;
string personcompanyid = doc1.SelectSingleNode("PERSONCOMPANY/PERSONCOMPANYID").InnerXml;
string lastname = doc1.SelectSingleNode("PERSONCOMPANY/LASTNAME").InnerXml;
string firstname = doc1.SelectSingleNode("PERSONCOMPANY/FIRSTNAME").InnerXml;
string fathername = doc1.SelectSingleNode("PERSONCOMPANY/FATHERNAME").InnerXml;
string companyname = doc1.SelectSingleNode("PERSONCOMPANY/COMPANYNAME").InnerXml;
string IDCARD = "";
if ((doc1.SelectSingleNode("PERSONCOMPANY/IDCARD")) is XmlNode)
{
IDCARD = doc1.SelectSingleNode("PERSONCOMPANY/IDCARD").InnerXml;
}
string TAXNUMBER = doc1.SelectSingleNode("PERSONCOMPANY/TAXNUMBER").InnerXml;
if ((doc1.SelectSingleNode("PERSONCOMPANY/IDCARD")) is XmlNode)
{
IDCARD = doc1.SelectSingleNode("PERSONCOMPANY/IDCARD").InnerXml;
}
string address = doc1.SelectSingleNode("PERSONCOMPANY/ADDRESS").InnerXml;
string CITY = doc1.SelectSingleNode("PERSONCOMPANY/CITY").InnerXml;
string COUNTY = doc1.SelectSingleNode("PERSONCOMPANY/COUNTY").InnerXml;
string PHONE = doc1.SelectSingleNode("PERSONCOMPANY/PHONE").InnerXml;
string POSTCODE = "";
if ((doc1.SelectSingleNode("PERSONCOMPANY/POSTCODE")) is XmlNode)
{
POSTCODE = doc1.SelectSingleNode("PERSONCOMPANY/POSTCODE").InnerXml;
}
//EISAGOUME TO ERWTHMA
//.........这里部分代码省略.........
示例14: SaveToFile
public void SaveToFile(Stream file)
{
XmlDocument dataDoc = new XmlDocument();
var camerasNode = dataDoc.CreateElement("Cameras");
var cam1Node = dataDoc.CreateElement("Camera");
var cam1AttNum = dataDoc.CreateAttribute("num");
cam1AttNum.Value = "1";
var cam1AttCalib = dataDoc.CreateAttribute("is_calibrated");
cam1AttCalib.Value = IsCamLeftCalibrated.ToString();
cam1Node.Attributes.Append(cam1AttNum);
cam1Node.Attributes.Append(cam1AttCalib);
if (IsCamLeftCalibrated)
{
cam1Node.InnerText = CamMatrixToString(CameraLeft);
}
camerasNode.AppendChild(cam1Node);
var cam2Node = dataDoc.CreateElement("Camera");
var cam2AttNum = dataDoc.CreateAttribute("num");
cam2AttNum.Value = "2";
var cam2AttCalib = dataDoc.CreateAttribute("is_calibrated");
cam2AttCalib.Value = IsCamRightCalibrated.ToString();
cam2Node.Attributes.Append(cam2AttNum);
cam2Node.Attributes.Append(cam2AttCalib);
if (IsCamRightCalibrated)
{
cam2Node.InnerText = CamMatrixToString(CameraRight);
}
camerasNode.AppendChild(cam2Node);
dataDoc.InsertAfter(camerasNode, dataDoc.DocumentElement);
dataDoc.Save(file);
}
示例15: SaveMap
private void SaveMap(Stream file, string path)
{
XmlDocument xmlDoc = new XmlDocument();
XmlNode mapNode = Map.CreateMapNode(xmlDoc);
xmlDoc.InsertAfter(mapNode, xmlDoc.DocumentElement);
xmlDoc.Save(file);
}