本文整理汇总了C#中XmlDocument.CreateDocumentFragment方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateDocumentFragment方法的具体用法?C# XmlDocument.CreateDocumentFragment怎么用?C# XmlDocument.CreateDocumentFragment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateDocumentFragment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAttributesOnDocumentFragment
public static void GetAttributesOnDocumentFragment()
{
var xmlDocument = new XmlDocument();
var documentFragment = xmlDocument.CreateDocumentFragment();
Assert.Null(documentFragment.Attributes);
}
示例2: GetSuccessCriteriaInfo
// 指定された達成基準の情報を返します。
public XmlNode GetSuccessCriteriaInfo(XmlDocument xml, string id)
{
DataRow r = this.Rows.Find(id);
XmlNode result = xml.CreateDocumentFragment();
string name = r[NameColumnName].ToString();
string level = r[LevelColumnName].ToString();
XmlElement sc = xml.CreateElement("SuccessCriteria");
XmlElement numberElement = xml.CreateElement("number");
numberElement.InnerText = id;
sc.AppendChild(numberElement);
XmlElement nameElement = xml.CreateElement("name");
nameElement.InnerText = name;
sc.AppendChild(nameElement);
XmlElement levelElement = xml.CreateElement("level");
levelElement.InnerText = level;
sc.AppendChild(levelElement);
result.AppendChild(sc);
return result;
}
示例3: CheckNodeType
public static void CheckNodeType()
{
var xmlDocument = new XmlDocument();
var documentFragment = xmlDocument.CreateDocumentFragment();
Assert.Equal(XmlNodeType.DocumentFragment, documentFragment.NodeType);
}
示例4: GetBodyElement
private XmlNode GetBodyElement(XmlDocument xml, string elementData)
{
string[] dataStrFragments = elementData.Split(NoticeSeparateChars.ToCharArray());
XmlNode result = xml.CreateDocumentFragment();
XmlElement body = xml.CreateElement("body");
string bodyData = null;
if(dataStrFragments.Length > 1){
bodyData = dataStrFragments[0];
for(int i = 1; i < dataStrFragments.Length; i++){
string noticeTitle = dataStrFragments[i];
if(++i >= dataStrFragments.Length) break;
string noticeBody = dataStrFragments[i];
XmlElement notice = xml.CreateElement("note");
result.AppendChild(notice);
AppendElement(notice, "noteTitle", noticeTitle);
AppendElement(notice, "noteBody", noticeBody);
}
} else {
bodyData = elementData;
}
if(!string.IsNullOrEmpty(bodyData)){
body.InnerText = bodyData;
result.PrependChild(body);
}
return result;
}
示例5: 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);
}
示例6: EmptyDocumentFragment
public static void EmptyDocumentFragment()
{
var xmlDocument = new XmlDocument();
var fragment = xmlDocument.CreateDocumentFragment();
fragment.Normalize();
Assert.Equal(String.Empty, fragment.OuterXml);
}
示例7: OnDocumentFragment
public static void OnDocumentFragment()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<root><child1/>some text<child2/><child3/></root>");
var documentFragment = xmlDocument.CreateDocumentFragment();
documentFragment.AppendChild(xmlDocument.DocumentElement);
Assert.Null(documentFragment.NextSibling);
}
示例8: DocumentFragment
public static void DocumentFragment()
{
var xmlDocument = new XmlDocument();
var fragment = xmlDocument.CreateDocumentFragment();
var text1 = xmlDocument.CreateTextNode("test_test1");
var text2 = xmlDocument.CreateTextNode("test_test2");
fragment.Normalize();
Assert.Equal(String.Empty, fragment.OuterXml);
}
示例9: AllNodesForEmptyString
public static void AllNodesForEmptyString()
{
var xml = "<root>\r\n text node one\r\n <elem1 child1=\"\" child2=\"duu\" child3=\"e1;e2;\" child4=\"a1\" child5=\"goody\">\r\n text node two e1; text node three\r\n </elem1><!-- comment3 --><?PI3 processing instruction?>e2;<foo /><![CDATA[ <opentag> without an </endtag> and & <! are all ok here ]]><elem2 att1=\"id1\" att2=\"up\" att3=\"attribute3\"><a /></elem2><elem2> \r\n elem2-text1\r\n <a> \r\n this-is-a \r\n </a> \r\n\r\n elem2-text2\r\n e3;e4;<!-- elem2-comment1-->\r\n elem2-text3\r\n\r\n <b> \r\n this-is-b\r\n </b>\r\n\r\n elem2-text4\r\n <?elem2_PI elem2-PI?>\r\n elem2-text5\r\n\r\n </elem2></root>";
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xml);
foreach (XmlNode node in xmlDocument.DocumentElement.ChildNodes)
Assert.Equal(String.Empty, node.NamespaceURI);
Assert.Equal(String.Empty, xmlDocument.CreateDocumentFragment().NamespaceURI);
}
示例10: 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);
}
示例11: 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);
}
示例12: RowToXml
public virtual XmlNode RowToXml(DataRow row, XmlDocument xml)
{
XmlNode result = xml.CreateDocumentFragment();
AppendElement(result, NumberColumnName, row[NumberColumnName]);
AppendElement(result, IdColumnName, row[IdColumnName]);
return result;
}
示例13: ReplaceElementWithDocumentFragmentNode
public static void ReplaceElementWithDocumentFragmentNode()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<root><child1/></root>");
var element = xmlDocument.DocumentElement.FirstChild;
var newDocumentFragment = xmlDocument.CreateDocumentFragment();
var result = xmlDocument.DocumentElement.ReplaceChild(newDocumentFragment, element);
Assert.Same(element, result);
Assert.Null(xmlDocument.DocumentElement.FirstChild);
}
示例14: 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);
}
示例15: FirstChildOfNewDocumentFragment
public static void FirstChildOfNewDocumentFragment()
{
var xmlDocument = new XmlDocument();
Assert.Null(xmlDocument.CreateDocumentFragment().FirstChild);
}