本文整理汇总了C#中System.Xml.XmlDocument.RemoveChild方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.RemoveChild方法的具体用法?C# XmlDocument.RemoveChild怎么用?C# XmlDocument.RemoveChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.RemoveChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromXml
/// <summary>
/// Converts the xml string parameter back to a class instance,
/// using the specified context for type mapping.
/// </summary>
public object FromXml( string xml, IMarshalContext context )
{
try
{
XmlDocument xmlDoc = new XmlDocument();
if (!xml.StartsWith(__rootElement))
xml = __rootElement + Environment.NewLine + xml;
xmlDoc.LoadXml( xml );
xmlDoc.RemoveChild(xmlDoc.FirstChild);
Type type = null;
IConverter converter = context.GetConverter( xmlDoc.FirstChild, ref type );
return converter.FromXml( null, null, type, xmlDoc.FirstChild, context );
}
catch ( ConversionException )
{
throw;
}
catch ( Exception e )
{
throw new ConversionException( e.Message, e );
}
finally
{
context.ClearStack();
}
}
示例2: SignFile
public override void SignFile(String xmlFilePath, object xmlDigitalSignature)
{
XmlElement XmlDigitalSignature = (XmlElement)xmlDigitalSignature;
XmlDocument Document = new XmlDocument();
Document.PreserveWhitespace = true;
XmlTextReader XmlFile = new XmlTextReader(xmlFilePath);
Document.Load(XmlFile);
XmlFile.Close();
// Append the element to the XML document.
Document.DocumentElement.AppendChild(Document.ImportNode(XmlDigitalSignature, true));
if (Document.FirstChild is XmlDeclaration)
{
Document.RemoveChild(Document.FirstChild);
}
// Save the signed XML document to a file specified
// using the passed string.
using (XmlTextWriter textwriter = new XmlTextWriter(xmlFilePath, new UTF8Encoding(false)))
{
textwriter.WriteStartDocument();
Document.WriteTo(textwriter);
textwriter.Close();
}
}
示例3: MergeContextIntoDocument
//--- Methods ---
public void MergeContextIntoDocument(XmlDocument document) {
if(document == null) {
throw new ArgumentNullException("document");
}
XmlElement root = document.DocumentElement;
if(root == null) {
throw new ArgumentNullException("document", "document is missing root element");
}
// check if we have to reorganize the document into an HTML document
if(((HeadItems.Count > 0) || (TailItems.Count > 0) || (Bodies.Count > 0)) && !StringUtil.EqualsInvariant(root.LocalName, "html") && !StringUtil.EqualsInvariant(root.LocalName, "content")) {
XmlElement html = document.CreateElement("html");
XmlElement body = document.CreateElement("body");
document.RemoveChild(root);
body.AppendChild(root);
html.AppendChild(body);
document.AppendChild(html);
root = document.DocumentElement;
}
// add head elements
if(HeadItems.Count > 0) {
XmlElement head = root["head"];
if(head == null) {
head = document.CreateElement("head");
root.AppendChild(head);
}
foreach(XmlNode item in HeadItems) {
head.AppendChild(document.ImportNode(item, true));
}
}
// add targetted bodies
foreach(KeyValuePair<string, List<XmlNode>> target in Bodies) {
XmlElement body = document.CreateElement("body");
root.AppendChild(body);
body.SetAttribute("target", target.Key);
foreach(XmlNode item in target.Value) {
foreach(XmlNode child in item.ChildNodes) {
body.AppendChild(document.ImportNode(child, true));
}
}
}
// add tail elements
if(TailItems.Count > 0) {
XmlElement tail = root["tail"];
if(tail == null) {
tail = document.CreateElement("tail");
root.AppendChild(tail);
}
foreach(XmlNode item in TailItems) {
tail.AppendChild(document.ImportNode(item, true));
}
}
}
示例4: Delete
public static void Delete(XmlDocument doc, string xPath)
{
if (doc != null)
{
XmlElement element = doc.DocumentElement;
if (doc.DocumentElement != null)
{
XmlNode node = doc.SelectSingleNode(xPath);
doc.RemoveChild(node);
}
}
}
示例5: RemoveHost
public static void RemoveHost(string host)
{
XmlDocument doc = new XmlDocument();
doc.Load(mapFile);
string hostName = host.ToLower().Trim();
XmlNode h = doc.SelectSingleNode("//Host[@name='" + hostName + "']");
if (h != null)
{
doc.RemoveChild(h);
doc.Save(mapFile);
}
}
示例6: Export
public void Export ()
{
byte [] salt = Convert.FromBase64String ("ofkHGOy0pioOd7++N2a52w==");
byte [] iv = Convert.FromBase64String ("OzFSoAlrfj11g246TM4How==");
XmlDocument doc = new XmlDocument ();
doc.Load ("Test/resources/rupert.xml");
doc.RemoveChild (doc.FirstChild);
byte [] result = new IdentityCardEncryption ().Encrypt (doc.OuterXml, "monkeydance", salt, iv);
string resultText = Encoding.UTF8.GetString (result);
string roundtrip = new IdentityCardEncryption ().Decrypt (resultText, "monkeydance");
doc = new XmlDocument ();
doc.LoadXml (roundtrip);
}
示例7: 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);
}
示例8: DeleteInventoryItem
public static string DeleteInventoryItem(string id, string xmlFileName)
{
string success = "ono";
try
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(xmlFileName);
XmlNode InventoryItemNode = xdoc.SelectSingleNode("//Inventory//Item[@Id='" + id + "']");
xdoc.RemoveChild(InventoryItemNode);
xdoc.Save(xmlFileName);
success = "ok";
}
catch (Exception ex) { success = "ERROR: " + ex.Message; }
return success;
}
示例9: AddSignatureToXmlDocument
private static void AddSignatureToXmlDocument(XmlDocument toSign, X509Certificate2 cert)
{
var signedXml = new SignedXml(toSign);
signedXml.SigningKey = cert.PrivateKey;
var reference = new Reference();
reference.Uri = "";
reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
signedXml.AddReference(reference);
signedXml.ComputeSignature();
var xmlDigitalSignature = signedXml.GetXml();
toSign.DocumentElement.AppendChild(toSign.ImportNode(xmlDigitalSignature, true));
if (toSign.FirstChild is XmlDeclaration) {
toSign.RemoveChild(toSign.FirstChild);
}
}
示例10: GenerateSignedXml
public string GenerateSignedXml(LicenseDetails details)
{
if (details == null)
throw new ArgumentNullException("details");
string rawXml;
var serializer = new XmlSerializer(typeof (LicenseDetails));
using (var stream = new MemoryStream())
{
serializer.Serialize(stream, details);
stream.Position = 0;
using (var streamReader = new StreamReader(stream))
rawXml = streamReader.ReadToEnd();
}
// Sign the xml
var doc = new XmlDocument();
TextReader reader = new StringReader(rawXml);
doc.Load(reader);
var signedXml = new SignedXml(doc);
signedXml.SigningKey = _key;
var reference = new Reference { Uri = "" };
reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
signedXml.AddReference(reference);
signedXml.ComputeSignature();
var signature = signedXml.GetXml();
if (doc.DocumentElement != null)
doc.DocumentElement.AppendChild(doc.ImportNode(signature, true));
if (doc.FirstChild is XmlDeclaration)
doc.RemoveChild(doc.FirstChild);
// Return the resulting xml
using (var stringWriter = new StringWriter())
using (var xmlTextWriter = XmlWriter.Create(stringWriter))
{
doc.WriteTo(xmlTextWriter);
xmlTextWriter.Flush();
return stringWriter.GetStringBuilder().ToString();
}
}
示例11: SaveRoundtrip
void SaveRoundtrip (string file)
{
IdentityCard ic = new IdentityCard ();
ic.Load (XmlReader.Create (file));
MemoryStream ms = new MemoryStream ();
XmlWriterSettings xws = new XmlWriterSettings ();
xws.OmitXmlDeclaration = true;
using (XmlWriter xw = XmlWriter.Create (ms, xws)) {
ic.Save (xw);
}
XmlDocument doc = new XmlDocument ();
doc.Load (file);
if (doc.FirstChild is XmlDeclaration)
doc.RemoveChild (doc.FirstChild);
string expected = doc.OuterXml;
doc.Load (new MemoryStream (ms.ToArray ()));
string actual = doc.OuterXml;
Assert.AreEqual (expected, actual, file);
}
示例12: SaveXmlButton_Click
private void SaveXmlButton_Click(object sender, EventArgs e)
{
var jsonString = jsonBox.Text;
var rawDoc = JsonConvert.DeserializeXmlNode(jsonString, this.rootNodeBox.Text, true);
// Here we are ensuring that the custom namespace shows up on the root node
// so that we have a nice clean message type on the request messages
var xmlDoc = new XmlDocument();
xmlDoc.AppendChild(xmlDoc.CreateElement("ns0", rawDoc.DocumentElement.LocalName, this.namespaceBox.Text));
xmlDoc.DocumentElement.InnerXml = rawDoc.DocumentElement.InnerXml;
var result = saveFileDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Yes || result == DialogResult.OK)
{
var outputFileName = saveFileDialog.FileName;
using (var writer = XmlWriter.Create(outputFileName))
{
xmlDoc.WriteTo(writer);
writer.Flush();
}
MessageBox.Show(string.Format("JSON data has been converted to XML and stored at:\r\n{0}", outputFileName),
"Success", MessageBoxButtons.OK);
// Re-load from the XML to verify that the document saved can still be read back as JSON data
XmlDocument savedDoc = new XmlDocument();
savedDoc.Load(outputFileName);
if (savedDoc.FirstChild.LocalName == "xml")
savedDoc.RemoveChild(savedDoc.FirstChild);
savedDoc.DocumentElement.Attributes.RemoveAll();
this.jsonBox.Text = JsonConvert.SerializeXmlNode(savedDoc, Newtonsoft.Json.Formatting.Indented, true);
}
}
示例13: firmarDocumento
public static string firmarDocumento(string documento, X509Certificate2 certificado)
{
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
String documento2 = documento;
doc.LoadXml(documento);
SignedXml signedXml = new SignedXml(doc);
signedXml.SigningKey = certificado.PrivateKey;
Signature XMLSignature = signedXml.Signature;
Reference reference = new Reference("");
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
XMLSignature.SignedInfo.AddReference(reference);
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new RSAKeyValue((RSA)certificado.PrivateKey));
keyInfo.AddClause(new KeyInfoX509Data(certificado));
XMLSignature.KeyInfo = keyInfo;
signedXml.ComputeSignature();
XmlElement xmlDigitalSignature = signedXml.GetXml();
doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, true));
if (doc.FirstChild is XmlDeclaration)
{
doc.RemoveChild(doc.FirstChild);
}
return doc.InnerXml;
}
示例14: Main
static void Main(string[] args)
{
try
{
Console.WriteLine("SnCore.Data.Mapping: fix hibernate mappings");
if (args.Length == 0)
{
Console.WriteLine("syntax: SnCore.Data.Mapping.exe [Project.csproj]");
throw new Exception("missing project name");
}
string projectFullPath = Path.GetFullPath(args[0]);
string projectFileName = Path.GetFileName(projectFullPath);
string projectDirectory = Path.GetDirectoryName(projectFullPath);
XmlDocument projectXml = new XmlDocument();
Console.WriteLine("Loading {0}", projectFullPath);
projectXml.Load(projectFullPath);
XmlNamespaceManager projectXmlNsMgr = new XmlNamespaceManager(projectXml.NameTable);
string msbuildns = "http://schemas.microsoft.com/developer/msbuild/2003";
projectXmlNsMgr.AddNamespace("msbuild", msbuildns);
// add all interface files to the project, IDbObject.cs, IDbPictureObject.cs, etc.
Console.WriteLine("Adding interface files ...");
AdditionalProjectFilesConfigurationSection additionalProjectFiles = (AdditionalProjectFilesConfigurationSection) ConfigurationManager.GetSection("AdditionalProjectFiles");
foreach (AdditionalProjectFileConfigurationElement interfaceFile in additionalProjectFiles.AdditionalProjectFiles)
{
string interfaceFileName = Path.GetFileName(interfaceFile.Filename);
Console.Write(" {0}: ", interfaceFileName);
XmlNode compileNode = projectXml.SelectSingleNode(
"/msbuild:Project/msbuild:ItemGroup/msbuild:Compile", projectXmlNsMgr);
if (compileNode == null)
{
throw new Exception("Missing Compile ItemGroup");
}
XmlNode compileItemGroupNode = compileNode.ParentNode;
XmlNode compileIncludeNode = compileItemGroupNode.SelectSingleNode(string.Format(
"msbuild:Compile[@Include='{0}']", interfaceFileName), projectXmlNsMgr);
if (compileIncludeNode == null)
{
compileIncludeNode = projectXml.CreateElement("Compile", msbuildns);
XmlAttribute compileIncludeNodeIncludeAttribute = projectXml.CreateAttribute("Include");
compileIncludeNodeIncludeAttribute.Value = interfaceFileName;
compileIncludeNode.Attributes.Append(compileIncludeNodeIncludeAttribute);
XmlElement subtypeElement = projectXml.CreateElement("SubType", msbuildns);
subtypeElement.AppendChild(projectXml.CreateTextNode("Code"));
compileIncludeNode.AppendChild(subtypeElement);
compileItemGroupNode.AppendChild(compileIncludeNode);
Console.WriteLine("added");
}
else
{
Console.WriteLine("skipped");
}
}
projectXml.Save(projectFullPath);
RemoveMappingConfigurationSection removeMappings = (RemoveMappingConfigurationSection)ConfigurationManager.GetSection("RemoveMappings");
foreach (RemoveMappingConfigurationElement removeMapping in removeMappings.RemoveMappings)
{
string mappingFileName = Path.Combine(projectDirectory, removeMapping.Class + ".hbm.xml");
Console.WriteLine(" {0}", Path.GetFileName(mappingFileName));
XmlDocument mappingXml = new XmlDocument();
mappingXml.Load(mappingFileName);
XmlNamespaceManager mappingXmlNsMgr = new XmlNamespaceManager(mappingXml.NameTable);
string hns = "urn:nhibernate-mapping-2.0";
mappingXmlNsMgr.AddNamespace("hns", hns);
XmlNode bagNode = mappingXml.SelectSingleNode(string.Format(
"//hns:bag[@name='{0}']", removeMapping.Bag), mappingXmlNsMgr);
if (bagNode != null)
{
Console.WriteLine(" Delete: {0}", removeMapping.Bag);
bagNode.ParentNode.RemoveChild(bagNode);
mappingXml.Save(mappingFileName);
}
}
foreach (string mappingFileName in Directory.GetFiles(projectDirectory, "*.hbm.xml"))
{
Console.WriteLine(" {0}", Path.GetFileName(mappingFileName));
XmlDocument mappingXml = new XmlDocument();
mappingXml.Load(mappingFileName);
XmlNamespaceManager mappingXmlNsMgr = new XmlNamespaceManager(mappingXml.NameTable);
string hns = "urn:nhibernate-mapping-2.0";
mappingXmlNsMgr.AddNamespace("hns", hns);
// get the mapping node
XmlNode hibernateMappingNode = mappingXml.SelectSingleNode("/hns:hibernate-mapping", mappingXmlNsMgr);
// remove puzzle comment
if (hibernateMappingNode != null)
{
if (hibernateMappingNode.PreviousSibling.NodeType == XmlNodeType.Comment)
mappingXml.RemoveChild(hibernateMappingNode.PreviousSibling);
//.........这里部分代码省略.........
示例15: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
var frameRate = Configuration.Settings.General.CurrentFrameRate;
var sb = new StringBuilder();
lines.ForEach(line => sb.AppendLine(line));
var xml = new XmlDocument { XmlResolver = null };
try
{
xml.LoadXml(sb.ToString().Trim());
var header = new XmlDocument { XmlResolver = null };
header.LoadXml(sb.ToString());
if (header.SelectSingleNode("sequence/media/video/track") != null)
header.RemoveChild(header.SelectSingleNode("sequence/media/video/track"));
subtitle.Header = header.OuterXml;
if (xml.DocumentElement.SelectSingleNode("sequence/rate") != null && xml.DocumentElement.SelectSingleNode("sequence/rate/timebase") != null)
{
try
{
frameRate = double.Parse(xml.DocumentElement.SelectSingleNode("sequence/rate/timebase").InnerText);
}
catch
{
frameRate = Configuration.Settings.General.CurrentFrameRate;
}
}
foreach (XmlNode node in xml.SelectNodes("xmeml/sequence/media/video/track"))
{
try
{
foreach (XmlNode generatorItemNode in node.SelectNodes("generatoritem"))
{
XmlNode rate = generatorItemNode.SelectSingleNode("rate");
if (rate != null)
{
XmlNode timebase = rate.SelectSingleNode("timebase");
if (timebase != null)
frameRate = double.Parse(timebase.InnerText);
}
double startFrame = 0;
double endFrame = 0;
XmlNode startNode = generatorItemNode.SelectSingleNode("start");
if (startNode != null)
startFrame = double.Parse(startNode.InnerText);
XmlNode endNode = generatorItemNode.SelectSingleNode("end");
if (endNode != null)
endFrame = double.Parse(endNode.InnerText);
string text = string.Empty;
foreach (XmlNode parameterNode in generatorItemNode.SelectNodes("effect/parameter[parameterid='str']"))
{
XmlNode valueNode = parameterNode.SelectSingleNode("value");
if (valueNode != null)
text += valueNode.InnerText;
}
bool italic = false;
bool bold = false;
foreach (XmlNode parameterNode in generatorItemNode.SelectNodes("effect/parameter[parameterid='style']"))
{
XmlNode valueNode = parameterNode.SelectSingleNode("value");
var valueEntries = parameterNode.SelectNodes("valuelist/valueentry");
if (valueNode != null)
{
int no;
if (int.TryParse(valueNode.InnerText, out no))
{
no--;
if (no < valueEntries.Count)
{
var styleNameNode = valueEntries[no].SelectSingleNode("name");
if (styleNameNode != null)
{
string styleName = styleNameNode.InnerText.ToLower().Trim();
italic = styleName == "italic" || styleName == "bold/italic";
bold = styleName == "bold" || styleName == "bold/italic";
}
}
}
}
}
if (!bold && !italic)
{
foreach (XmlNode parameterNode in generatorItemNode.SelectNodes("effect/parameter[parameterid='fontstyle']"))
{
XmlNode valueNode = parameterNode.SelectSingleNode("value");
var valueEntries = parameterNode.SelectNodes("valuelist/valueentry");
if (valueNode != null)
{
int no;
if (int.TryParse(valueNode.InnerText, out no))
{
no--;
if (no < valueEntries.Count)
//.........这里部分代码省略.........