本文整理汇总了C#中XmlDocument.CreateComment方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateComment方法的具体用法?C# XmlDocument.CreateComment怎么用?C# XmlDocument.CreateComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateComment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NameOfAllTypes
public static void NameOfAllTypes()
{
var xmlDocument = new XmlDocument();
var element = xmlDocument.CreateElement("newElem");
Assert.Equal("newElem", element.Name);
var attribute = xmlDocument.CreateAttribute("newAttr");
Assert.Equal("newAttr", attribute.Name);
var text = xmlDocument.CreateTextNode("");
Assert.Equal("#text", text.Name);
var cdata = xmlDocument.CreateCDataSection("");
Assert.Equal("#cdata-section", cdata.Name);
var pi = xmlDocument.CreateProcessingInstruction("PI", "");
Assert.Equal("PI", pi.Name);
var comment = xmlDocument.CreateComment("some text");
Assert.Equal("#comment", comment.Name);
var fragment = xmlDocument.CreateDocumentFragment();
Assert.Equal("#document-fragment", fragment.Name);
}
示例2: CreateEmptyComment
public static void CreateEmptyComment()
{
var xmlDocument = new XmlDocument();
var comment = xmlDocument.CreateComment(String.Empty);
Assert.Equal("<!---->", comment.OuterXml);
Assert.Equal(String.Empty, comment.InnerText);
Assert.Equal(comment.NodeType, XmlNodeType.Comment);
}
示例3: ImportDocumentFragment
public static void ImportDocumentFragment()
{
var tempDoc = new XmlDocument();
var nodeToImport = tempDoc.CreateDocumentFragment();
nodeToImport.AppendChild(tempDoc.CreateElement("A1"));
nodeToImport.AppendChild(tempDoc.CreateComment("comment"));
nodeToImport.AppendChild(tempDoc.CreateProcessingInstruction("PI", "donothing"));
var xmlDocument = new XmlDocument();
var node = xmlDocument.ImportNode(nodeToImport, true);
Assert.Equal(xmlDocument, node.OwnerDocument);
Assert.Equal(XmlNodeType.DocumentFragment, node.NodeType);
Assert.Equal(nodeToImport.OuterXml, node.OuterXml);
}
示例4: OwnerDocumentOnImportedTree
public static void OwnerDocumentOnImportedTree()
{
var tempDoc = new XmlDocument();
var nodeToImport = tempDoc.CreateDocumentFragment();
nodeToImport.AppendChild(tempDoc.CreateElement("A1"));
nodeToImport.AppendChild(tempDoc.CreateComment("comment"));
nodeToImport.AppendChild(tempDoc.CreateProcessingInstruction("PI", "donothing"));
var xmlDocument = new XmlDocument();
var node = xmlDocument.ImportNode(nodeToImport, true);
Assert.Equal(xmlDocument, node.OwnerDocument);
foreach (XmlNode child in node.ChildNodes)
Assert.Equal(xmlDocument, child.OwnerDocument);
}
示例5: CreateNode
public static XmlNode CreateNode(XmlDocument doc, XmlNodeType nodeType)
{
Assert.NotNull(doc);
switch (nodeType)
{
case XmlNodeType.CDATA:
return doc.CreateCDataSection(@"< & <tag> < ! > & </tag> ");
case XmlNodeType.Comment:
return doc.CreateComment(@"comment");
case XmlNodeType.Element:
return doc.CreateElement("E");
case XmlNodeType.Text:
return doc.CreateTextNode("text");
case XmlNodeType.Whitespace:
return doc.CreateWhitespace(@" ");
case XmlNodeType.SignificantWhitespace:
return doc.CreateSignificantWhitespace(" ");
default:
throw new ArgumentException("Wrong XmlNodeType: '" + nodeType + "'");
}
}
示例6: CommentNode
public static void CommentNode()
{
var xmlDocument = new XmlDocument();
var node = xmlDocument.CreateComment("comment");
Assert.Equal("comment", node.Value);
node.Value = "new comment";
Assert.Equal("new comment", node.Value);
}
示例7: ExportInputManager
public static bool ExportInputManager(RUISInputManager inputManager, string filename)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
XmlElement inputManagerRootElement = xmlDoc.CreateElement("ns2", "RUISInputManager", "http://ruisystem.net/RUISInputManager");
xmlDoc.AppendChild(inputManagerRootElement);
XmlComment booleanComment = xmlDoc.CreateComment("Boolean values always with a lower case, e.g. \"true\" or \"false\"");
inputManagerRootElement.AppendChild(booleanComment);
XmlElement psMoveSettingsElement = xmlDoc.CreateElement("PSMoveSettings");
inputManagerRootElement.AppendChild(psMoveSettingsElement);
XmlElement psMoveEnabledElement = xmlDoc.CreateElement("enabled");
psMoveEnabledElement.SetAttribute("value", inputManager.enablePSMove.ToString().ToLowerInvariant());
psMoveSettingsElement.AppendChild(psMoveEnabledElement);
XmlElement psMoveIPElement = xmlDoc.CreateElement("ip");
psMoveIPElement.SetAttribute("value", inputManager.PSMoveIP.ToString());
psMoveSettingsElement.AppendChild(psMoveIPElement);
XmlElement psMovePortElement = xmlDoc.CreateElement("port");
psMovePortElement.SetAttribute("value", inputManager.PSMovePort.ToString());
psMoveSettingsElement.AppendChild(psMovePortElement);
XmlElement psMoveAutoConnectElement = xmlDoc.CreateElement("autoConnect");
psMoveAutoConnectElement.SetAttribute("value", inputManager.connectToPSMoveOnStartup.ToString().ToLowerInvariant());
psMoveSettingsElement.AppendChild(psMoveAutoConnectElement);
XmlElement psMoveEnableInGameCalibration = xmlDoc.CreateElement("enableInGameCalibration");
psMoveEnableInGameCalibration.SetAttribute("value", inputManager.enableMoveCalibrationDuringPlay.ToString().ToLowerInvariant());
psMoveSettingsElement.AppendChild(psMoveEnableInGameCalibration);
XmlElement psMoveMaxControllersElement = xmlDoc.CreateElement("maxControllers");
psMoveMaxControllersElement.SetAttribute("value", inputManager.amountOfPSMoveControllers.ToString());
psMoveSettingsElement.AppendChild(psMoveMaxControllersElement);
XmlElement kinectSettingsElement = xmlDoc.CreateElement("KinectSettings");
inputManagerRootElement.AppendChild(kinectSettingsElement);
XmlElement kinectEnabledElement = xmlDoc.CreateElement("enabled");
kinectEnabledElement.SetAttribute("value", inputManager.enableKinect.ToString().ToLowerInvariant());
kinectSettingsElement.AppendChild(kinectEnabledElement);
XmlElement maxKinectPlayersElement = xmlDoc.CreateElement("maxPlayers");
maxKinectPlayersElement.SetAttribute("value", inputManager.maxNumberOfKinectPlayers.ToString());
kinectSettingsElement.AppendChild(maxKinectPlayersElement);
XmlElement kinectFloorDetectionElement = xmlDoc.CreateElement("floorDetection");
kinectFloorDetectionElement.SetAttribute("value", inputManager.kinectFloorDetection.ToString().ToLowerInvariant());
kinectSettingsElement.AppendChild(kinectFloorDetectionElement);
XmlElement jumpGestureElement = xmlDoc.CreateElement("jumpGestureEnabled");
jumpGestureElement.SetAttribute("value", inputManager.jumpGestureEnabled.ToString().ToLowerInvariant());
kinectSettingsElement.AppendChild(jumpGestureElement);
XmlElement kinect2SettingsElement = xmlDoc.CreateElement("Kinect2Settings");
inputManagerRootElement.AppendChild(kinect2SettingsElement);
XmlElement kinect2EnabledElement = xmlDoc.CreateElement("enabled");
kinect2EnabledElement.SetAttribute("value", inputManager.enableKinect2.ToString().ToLowerInvariant());
kinect2SettingsElement.AppendChild(kinect2EnabledElement);
XmlElement kinect2FloorDetectionElement = xmlDoc.CreateElement("floorDetection");
kinect2FloorDetectionElement.SetAttribute("value", inputManager.kinect2FloorDetection.ToString().ToLowerInvariant());
kinect2SettingsElement.AppendChild(kinect2FloorDetectionElement);
XmlElement razerSettingsElement = xmlDoc.CreateElement("RazerSettings");
inputManagerRootElement.AppendChild(razerSettingsElement);
XmlElement razerEnabledElement = xmlDoc.CreateElement("enabled");
razerEnabledElement.SetAttribute("value", inputManager.enableRazerHydra.ToString().ToLowerInvariant());
razerSettingsElement.AppendChild(razerEnabledElement);
XmlElement riftDriftSettingsElement = xmlDoc.CreateElement("OculusDriftSettings");
inputManagerRootElement.AppendChild(riftDriftSettingsElement);
//XmlElement magnetometerDriftCorrectionElement = xmlDoc.CreateElement("magnetometerDriftCorrection");
//magnetometerDriftCorrectionElement.SetAttribute("value", System.Enum.GetName(typeof(RUISInputManager.RiftMagnetometer), inputManager.riftMagnetometerMode));
//riftDriftSettingsElement.AppendChild(magnetometerDriftCorrectionElement);
XmlElement kinectDriftCorrectionElement = xmlDoc.CreateElement("kinectDriftCorrectionIfAvailable");
kinectDriftCorrectionElement.SetAttribute("value", inputManager.kinectDriftCorrectionPreferred.ToString().ToLowerInvariant());
riftDriftSettingsElement.AppendChild(kinectDriftCorrectionElement);
XMLUtil.SaveXmlToFile(filename, xmlDoc);
return true;
}
示例8: ElementNodeWithOneChildDeleteItInsertTwoNewChildren
public static void ElementNodeWithOneChildDeleteItInsertTwoNewChildren()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<top><child /></top>");
xmlDocument.DocumentElement.RemoveChild(xmlDocument.DocumentElement.FirstChild);
var newNode1 = xmlDocument.CreateTextNode("text node");
var newNode2 = xmlDocument.CreateComment("comment here");
xmlDocument.DocumentElement.AppendChild(newNode1);
xmlDocument.DocumentElement.AppendChild(newNode2);
Assert.NotNull(xmlDocument.DocumentElement.FirstChild);
Assert.Same(newNode1, xmlDocument.DocumentElement.FirstChild);
}
示例9: FirstChildOfNewDocumentFragmentWithChildren
public static void FirstChildOfNewDocumentFragmentWithChildren()
{
var xmlDocument = new XmlDocument();
var fragment = xmlDocument.CreateDocumentFragment();
var node1 = xmlDocument.CreateComment("comment");
var node2 = xmlDocument.CreateCDataSection("some random text");
fragment.AppendChild(node1);
fragment.AppendChild(node2);
Assert.Same(node1, fragment.FirstChild);
}
示例10: FirstChildOfNewComment
public static void FirstChildOfNewComment()
{
var xmlDocument = new XmlDocument();
Assert.Null(xmlDocument.CreateComment("a comment").FirstChild);
}
示例11: CheckNoChildrenOnComment
public static void CheckNoChildrenOnComment()
{
var xmlDocument = new XmlDocument();
Assert.False(xmlDocument.CreateComment("info").HasChildNodes);
}
示例12: NewlyCreatedComment
public static void NewlyCreatedComment()
{
var xmlDocument = new XmlDocument();
var node = xmlDocument.CreateComment("comment");
Assert.Null(node.NextSibling);
}
示例13: CommentChildNodeCount
public static void CommentChildNodeCount()
{
var xmlDocument = new XmlDocument();
var item = xmlDocument.CreateComment("comment");
var clonedTrue = item.CloneNode(true);
var clonedFalse = item.CloneNode(false);
Assert.Equal(0, item.ChildNodes.Count);
Assert.Equal(0, clonedTrue.ChildNodes.Count);
Assert.Equal(0, clonedFalse.ChildNodes.Count);
}
示例14: InsertCommentNodeToDocument
public static void InsertCommentNodeToDocument()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<root/>");
var node = xmlDocument.CreateComment("some comment");
Assert.Equal(0, xmlDocument.DocumentElement.ChildNodes.Count);
var result = xmlDocument.DocumentElement.InsertBefore(node, null);
Assert.Same(node, result);
Assert.Equal(1, xmlDocument.DocumentElement.ChildNodes.Count);
}
示例15: InsertCommentNodeToDocumentFragment
public static void InsertCommentNodeToDocumentFragment()
{
var xmlDocument = new XmlDocument();
var documentFragment = xmlDocument.CreateDocumentFragment();
var node = xmlDocument.CreateComment("some comment");
Assert.Equal(0, documentFragment.ChildNodes.Count);
var result = documentFragment.InsertBefore(node, null);
Assert.Same(node, result);
Assert.Equal(1, documentFragment.ChildNodes.Count);
}