本文整理汇总了C#中XmlDocument.RemoveChild方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.RemoveChild方法的具体用法?C# XmlDocument.RemoveChild怎么用?C# XmlDocument.RemoveChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.RemoveChild方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetXml
/// <summary>
/// To Create Xml file for every multiselect list to pass data of xml type in database
/// </summary>
/// <param name="DtXml"></param>
/// <param name="Text"></param>
/// <param name="Value"></param>
/// <param name="XmlFileName"></param>
/// <returns></returns>
public string GetXml(DataTable DtXml, String Text, String Value,string XmlFileName)
{
XmlDocument xmldoc = new XmlDocument();
//To create Xml declarartion in xml file
XmlDeclaration decl = xmldoc.CreateXmlDeclaration("1.0", "UTF-16", "");
xmldoc.InsertBefore(decl, xmldoc.DocumentElement);
XmlElement RootNode = xmldoc.CreateElement("Root");
xmldoc.AppendChild(RootNode);
for (int i = 0; i < DtXml.Rows.Count; i++)
{
XmlElement childNode = xmldoc.CreateElement("Row");
childNode.SetAttribute(Value, DtXml.Rows[i][1].ToString());
childNode.SetAttribute(Text, DtXml.Rows[i][0].ToString());
RootNode.AppendChild(childNode);
}
//Check if directory already exist or not otherwise
//create directory
if (!Directory.Exists(System.Web.HttpContext.Current.Server.MapPath("XML")))
Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath("XML"));
XmlFileName = "XML" + "\\" + XmlFileName;
//To save xml file on respective path
xmldoc.Save(System.Web.HttpContext.Current.Server.MapPath(XmlFileName));
xmldoc.RemoveChild(xmldoc.FirstChild);
string RetXml = xmldoc.InnerXml;
return RetXml;
}
示例2: RemoveDocumentElement
public static void RemoveDocumentElement()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<?PI pi1?><root><child1/><child2/><child3/></root><!--comment-->");
var root = xmlDocument.DocumentElement;
Assert.Equal(3, xmlDocument.ChildNodes.Count);
xmlDocument.RemoveChild(root);
Assert.Equal(2, xmlDocument.ChildNodes.Count);
Assert.Equal(XmlNodeType.ProcessingInstruction, xmlDocument.ChildNodes[0].NodeType);
Assert.Equal(XmlNodeType.Comment, xmlDocument.ChildNodes[1].NodeType);
}
示例3: SignXmlFile
// Sign an XML file and save the signature in a new file. This method does not
// save the public key within the XML file. This file cannot be verified unless
// the verifying code has the key with which it was signed.
public static void SignXmlFile(string FileName, string SignedFileName, RSA Key)
{
// Create a new XML document.
XmlDocument doc = new XmlDocument();
// Load the passed XML file using its name.
doc.Load(new XmlTextReader(FileName));
// Create a SignedXml object.
SignedXml signedXml = new SignedXml(doc);
// Add the key to the SignedXml document.
signedXml.SigningKey = Key;
// Create a reference to be signed.
Reference reference = new Reference();
reference.Uri = "";
// Add an enveloped transformation to the reference.
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
// Add the reference to the SignedXml object.
signedXml.AddReference(reference);
// Compute the signature.
signedXml.ComputeSignature();
// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement xmlDigitalSignature = signedXml.GetXml();
// Append the element to the XML document.
doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, true));
if (doc.FirstChild is XmlDeclaration)
{
doc.RemoveChild(doc.FirstChild);
}
// Save the signed XML document to a file specified
// using the passed string.
XmlTextWriter xmltw = new XmlTextWriter(SignedFileName, new UTF8Encoding(false));
doc.WriteTo(xmltw);
xmltw.Close();
}
示例4: Assinar
public static XmlDocument Assinar(XmlDocument docXML, string pUri, X509Certificate2 pCertificado)
{
try {
// Load the certificate from the certificate store.
X509Certificate2 cert = pCertificado;
// Create a new XML document.
XmlDocument doc = new XmlDocument();
// Format the document to ignore white spaces.
doc.PreserveWhitespace = false;
// Load the passed XML file using it's name.
doc = docXML;
// Create a SignedXml object.
SignedXml signedXml = new SignedXml(doc);
// Add the key to the SignedXml document.
signedXml.SigningKey = cert.PrivateKey;
// Create a reference to be signed.
Reference reference = new Reference();
// pega o uri que deve ser assinada
XmlAttributeCollection _Uri = doc.GetElementsByTagName(pUri).Item(0).Attributes;
foreach (XmlAttribute _atributo in _Uri) {
if (_atributo.Name == "Id") {
reference.Uri = "#" + _atributo.InnerText;
}
}
// Add an enveloped transformation to the reference.
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
XmlDsigC14NTransform c14 = new XmlDsigC14NTransform();
reference.AddTransform(c14);
// Add the reference to the SignedXml object.
signedXml.AddReference(reference);
// Create a new KeyInfo object.
KeyInfo keyInfo = new KeyInfo();
// Load the certificate into a KeyInfoX509Data object
// and add it to the KeyInfo object.
keyInfo.AddClause(new KeyInfoX509Data(cert));
// Add the KeyInfo object to the SignedXml object.
signedXml.KeyInfo = keyInfo;
// Compute the signature.
signedXml.ComputeSignature();
// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement xmlDigitalSignature = signedXml.GetXml();
// Append the element to the XML document.
doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, true));
if (doc.FirstChild is XmlDeclaration) {
doc.RemoveChild(doc.FirstChild);
}
return doc;
} catch (Exception ex) {
throw new Exception("Erro ao efetuar assinatura digital, detalhes: " + ex.Message);
}
}
示例5: ConvertObjectToXml
public string ConvertObjectToXml(Object objData)
{
try
{
var xmlDoc = new XmlDocument(); //Represents an XML document,
// Initializes a new instance of the XmlDocument class.
var xmlSerializer = new XmlSerializer(objData.GetType());
// Create empty namespace
var namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);
// Creates a stream whose backing store is memory.
using (var xmlStream = new MemoryStream())
{
xmlSerializer.Serialize(xmlStream, objData, namespaces);
xmlStream.Position = 0;
//Loads the XML document from the specified string.
xmlDoc.Load(xmlStream);
foreach (XmlNode node in xmlDoc)
{
if (node.NodeType == XmlNodeType.XmlDeclaration)
{
xmlDoc.RemoveChild(node);
}
}
return xmlDoc.InnerXml;
}
}
catch (Exception ex)
{
return ex.Message;
}
}