当前位置: 首页>>代码示例>>C#>>正文


C# XmlDocument.RemoveChild方法代码示例

本文整理汇总了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();
			}
		}
开发者ID:jxqlovejava,项目名称:Tatala-RPC,代码行数:35,代码来源:XStreamMarshaller.cs

示例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();
            }
        }
开发者ID:usnistgov,项目名称:DT4SM,代码行数:25,代码来源:XML4PLOT.cs

示例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));
                }
            }
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:57,代码来源:DekiScriptEvalContext.cs

示例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);
                }
            }
        }
开发者ID:TrakHound,项目名称:TrakHound-Community,代码行数:13,代码来源:Nodes.cs

示例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);
            }
        }
开发者ID:foresightbrand,项目名称:kebibi,代码行数:13,代码来源:MinisiteMap.cs

示例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);
		}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:14,代码来源:IdentityCardEncryptionTest.cs

示例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);
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:15,代码来源:RemoveChildTests.cs

示例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;
 }
开发者ID:CurtisRhodes,项目名称:LodgeSecretary,代码行数:15,代码来源:InventoryDataXml.cs

示例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);
            }
        }
开发者ID:brianmcmichael,项目名称:DesktopBootstrap,代码行数:17,代码来源:Form1.cs

示例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();
            }
        }
开发者ID:KallDrexx,项目名称:ELiS,代码行数:44,代码来源:LicenseGenerator.cs

示例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);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:19,代码来源:IdentityCardTest.cs

示例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);

            }

        }
开发者ID:HydAu,项目名称:QLBizTalk2013,代码行数:41,代码来源:MainForm.cs

示例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;
        }
开发者ID:osvaldomiranda,项目名称:AdmToFebos,代码行数:40,代码来源:xmlAdmin.cs

示例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);

//.........这里部分代码省略.........
开发者ID:dblock,项目名称:sncore,代码行数:101,代码来源:Program.cs

示例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)
//.........这里部分代码省略.........
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:101,代码来源:FinalCutProTextXml.cs


注:本文中的System.Xml.XmlDocument.RemoveChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。