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


C# XmlDocument.Clone方法代码示例

本文整理汇总了C#中System.Xml.XmlDocument.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.Clone方法的具体用法?C# XmlDocument.Clone怎么用?C# XmlDocument.Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlDocument的用法示例。


在下文中一共展示了XmlDocument.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadProperties

 protected void LoadProperties(string source)
 {
     XmlDocument document = new XmlDocument();
     document.LoadXml(source);
     XmlNodeList elementsByTagName = document.GetElementsByTagName("Property");
     this.mPropertyDoc = (XmlDocument) document.Clone();
     XmlElement element = this.mPropertyDoc.CreateElement("properties");
     string str = "";
     XmlNode newChild = null;
     foreach (XmlNode node2 in elementsByTagName)
     {
         XmlAttribute namedItem = (XmlAttribute) node2.Attributes.GetNamedItem("control");
         if (str != namedItem.Value)
         {
             newChild = element.OwnerDocument.CreateElement(namedItem.Value);
             element.AppendChild(newChild);
             str = namedItem.Value;
         }
         XmlElement element2 = newChild.OwnerDocument.CreateElement("Property");
         for (int i = 0; i < node2.Attributes.Count; i++)
         {
             element2.SetAttribute(node2.Attributes[i].Name, node2.Attributes[i].Value);
         }
         newChild.AppendChild(element2);
     }
     this.Controls = new ControlCollection(element.ChildNodes);
 }
开发者ID:huamanhtuyen,项目名称:VNACCS,代码行数:27,代码来源:PropertiesCollection.cs

示例2: Apply

        /// <inheritdoc />
        public override void Apply(XmlDocument document, string key)
        {
            foreach(IEnumerable<BuildComponentCore> branch in branches)
            {
                XmlDocument subdocument = document.Clone() as XmlDocument;

                foreach(BuildComponentCore component in branch)
                    component.Apply(subdocument, key);
            }
        }
开发者ID:modulexcite,项目名称:SHFB-1,代码行数:11,代码来源:CloneComponent.cs

示例3: writeStrict

        public static string writeStrict(XmlDocument original)
        {
            Debug.Assert(original.DocumentType == null);
            const string DocType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
            var document = (XmlDocument)original.Clone();
            addHTMLStringNamespaceToRootElement(document);

            using (var stringWriter = new StringWriter())
            {
                using (var textWriter = new XHTMLTextWriter(stringWriter))
                {
                    document.WriteTo(textWriter);
                }

                return DocType + stringWriter;
            }
        }
开发者ID:pragmatrix,项目名称:SiteSharper,代码行数:17,代码来源:XHTMLWriter.cs

示例4: Test

        //--- Class Methods ---
        private static void Test(string name, XmlRender xmlRender, CaseFolding caseFolding, string doctype, bool format) {
            string source;
            string expected;
            ReadTest(name, out source, out expected);
            expected = expected.Trim().Replace("\r", "");
            string actual;

            // determine how the document should be written back
            XmlReaderTestCallback callback;
            switch(xmlRender) {
            case XmlRender.Doc:

                // test writing sgml reader using xml document load
                callback = (reader, writer) => {
                    var doc = new XmlDocument();
                    doc.Load(reader);
                    doc.WriteTo(writer);
                };
                break;
            case XmlRender.DocClone:

                // test writing sgml reader using xml document load and clone
                callback = (reader, writer) => {
                    var doc = new XmlDocument();
                    doc.Load(reader);
                    var clone = doc.Clone();
                    clone.WriteTo(writer);
                };
                break;
            case XmlRender.Passthrough:

                // test writing sgml reader directly to xml writer
                callback = (reader, writer) => {
                    reader.Read();
                    while(!reader.EOF) {
                        writer.WriteNode(reader, true);
                    }
                };
                break;
            default:
                throw new ArgumentException("unknown value", "xmlRender");
            }
            actual = RunTest(caseFolding, doctype, format, source, callback);
            Assert.AreEqual(expected, actual);
        }
开发者ID:VitaliyBoris,项目名称:SGMLReader,代码行数:46,代码来源:Tests-Logic.cs

示例5: loadLevel

 public static void loadLevel(ContentManager c, String path)
 {
     c.clear();
     XmlDocument reader = new XmlDocument();
     reader.Load(path);
     int id = 0;
     float[] blockInfo = new float[4];
     foreach(XmlNode node in reader.DocumentElement)
     {
         foreach(XmlNode child in node.ChildNodes)
         {
             id = int.Parse(child.Attributes[0].Value);
             blockInfo[0] = float.Parse(child.Attributes[1].Value);
             blockInfo[1] = float.Parse(child.Attributes[2].Value);
             blockInfo[2] = float.Parse(child.Attributes[3].Value);
             blockInfo[3] = float.Parse(child.Attributes[4].Value);
             loadBlock(id, blockInfo, c);
         }
     }
     reader.Clone();
 }
开发者ID:Raptor2277,项目名称:CubePlatformer,代码行数:21,代码来源:IO.cs

示例6: FormatXmlDocument

        /// <summary>
        /// Takes an xml doc and trims whitespace from its children and removes any newlines
        /// </summary>
        /// <param name="doc">
        /// The XmlDocument to format.
        /// </param>
        /// <returns>
        /// An XmlDocument nicely formatted.
        /// </returns>
        private static XmlDocument FormatXmlDocument(XmlDocument doc)
        {
            XmlDocument formattedDoc = (XmlDocument)doc.Clone();

            // merge consecutive text nodes so avoid handling whitespace between
            // those
            formattedDoc.Normalize();

            Queue<XmlNode> queue = new Queue<XmlNode>();
            queue.Enqueue(formattedDoc.DocumentElement);

            while (queue.Count > 0)
            {
                XmlNode currentNode = queue.Dequeue();
                XmlNodeList childNodes = currentNode.ChildNodes;
                for (int i = 0; i < childNodes.Count; ++i)
                {
                    XmlNode child = childNodes[i];
                    if (child.NodeType != XmlNodeType.Text)
                    {
                        queue.Enqueue(child);
                        continue;
                    }

                    string text = child.InnerText.TrimEnd().Replace(" \n", "\n");
                    text = text.Replace("\n ", "\n");
                    text = text.Replace("\n\n\n\n", " ");
                    text = text.Replace("\n\n\n", " ");
                    text = text.Replace("\n\n", " ");
                    text = text.Replace("\n", " ");

                    if (i != childNodes.Count - 1)
                    {
                        text = text + " ";
                    }

                    child.InnerText = text;
                }
            }

            return formattedDoc;
        }
开发者ID:kjata30,项目名称:StyleCop,代码行数:51,代码来源:DocumentationRules.cs

示例7: SetContentEveloping

        /// <summary>
        /// Inserta un contenido XML para generar una firma enveloping.
        /// </summary>
        /// <param name="xmlDocument"></param>
        public void SetContentEveloping(XmlDocument xmlDocument)
        {
            Reference reference = new Reference();

            _xadesSignedXml = new XadesSignedXml();

            XmlDocument doc = (XmlDocument)xmlDocument.Clone();
            doc.PreserveWhitespace = true;

            if (doc.ChildNodes[0].NodeType == XmlNodeType.XmlDeclaration)
            {
                doc.RemoveChild(doc.ChildNodes[0]);
            }

            //Add an object
            string dataObjectId = "DataObject-" + Guid.NewGuid().ToString();
            System.Security.Cryptography.Xml.DataObject dataObject = new System.Security.Cryptography.Xml.DataObject();
            dataObject.Data = doc.ChildNodes;
            dataObject.Id = dataObjectId;
            _xadesSignedXml.AddObject(dataObject);

            reference.Id = "Reference-" + Guid.NewGuid().ToString();
            reference.Uri = "#" + dataObjectId;
            reference.Type = SignedXml.XmlDsigNamespaceUrl + "Object";

            XmlDsigC14NTransform transform = new XmlDsigC14NTransform();
            reference.AddTransform(transform);

            _objectReference = reference.Id;
            _mimeType = "text/xml";

            _xadesSignedXml.AddReference(reference);

            _document = null;
        }
开发者ID:zinkpad,项目名称:FirmaXadesNet45,代码行数:39,代码来源:FirmaXades.cs

示例8: SetContentInternallyDetached

        /// <summary>
        /// Carga el documento XML especificado y establece para firmar el elemento especificado en elementId
        /// </summary>
        /// <param name="xmlDocument"></param>
        /// <param name="elementId"></param>
        /// <param name="mimeType"></param>
        public void SetContentInternallyDetached(XmlDocument xmlDocument, string elementId, string mimeType)
        {
            _document = (XmlDocument)xmlDocument.Clone();
            _document.PreserveWhitespace = true;

            Reference reference = new Reference();

            reference.Uri = "#" + elementId;
            reference.Id = "Reference-" + Guid.NewGuid().ToString();

            _objectReference = reference.Id;
            _mimeType = mimeType;

            if (mimeType == "text/xml")
            {
                XmlDsigC14NTransform transform = new XmlDsigC14NTransform();
                reference.AddTransform(transform);
            }
            else
            {
                XmlDsigBase64Transform transform = new XmlDsigBase64Transform();
                reference.AddTransform(transform);
            }

            _xadesSignedXml = new XadesSignedXml(_document);

            _xadesSignedXml.AddReference(reference);
        }
开发者ID:zinkpad,项目名称:FirmaXadesNet45,代码行数:34,代码来源:FirmaXades.cs

示例9: RunTest

 void RunTest(SgmlReader reader, int line, string args, string input, string expectedOutput){
     bool testdoc = false;
     bool testclone = false;
     foreach (string arg in args.Split(' ')){
         string sarg = arg.Trim();
         if (sarg.Length==0) continue;
         if (sarg[0] == '-'){
             switch (sarg.Substring(1)){
                 case "html":
                     reader.DocType = "html";
                     break;
                 case "lower":
                     reader.CaseFolding = CaseFolding.ToLower;
                     break;
                 case "upper":
                     reader.CaseFolding = CaseFolding.ToUpper;
                     break;
                 case "testdoc":
                     testdoc = true;
                     break;
                 case "testclone":
                     testclone = true;
                     break;
             }
         }
     }
     this.tests++;
     reader.InputStream = new StringReader(input);
     reader.WhitespaceHandling = WhitespaceHandling.None;
     StringWriter output = new StringWriter();
     XmlTextWriter w = new XmlTextWriter(output);
     w.Formatting = Formatting.Indented;
     if (testdoc) {
         XmlDocument doc = new XmlDocument();
         doc.Load(reader);
         doc.WriteTo(w);
     } else if(testclone) {
         XmlDocument doc = new XmlDocument();
         doc.Load(reader);
         XmlNode clone = doc.Clone();
         clone.WriteTo(w);
     } else {
         reader.Read();
         while (!reader.EOF) {
             w.WriteNode(reader, true);
         }
     }            
     w.Close();
     string actualOutput = output.ToString();
     if (actualOutput.Trim() != expectedOutput.Trim()) {
         Console.WriteLine();
         Console.WriteLine("ERROR: Test failed on line {0}", line);
         Console.WriteLine("---- Expected output");
         Console.Write(expectedOutput);
         Console.WriteLine("---- Actual output");
         Console.WriteLine(actualOutput);
     } else {
         this.passed++;
     }
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:60,代码来源:Test.cs

示例10: SetContentEnveloped

        /// <summary>
        /// Inserta un contenido XML para generar una firma enveloped.
        /// </summary>
        /// <param name="xmlDocument"></param>
        public void SetContentEnveloped(XmlDocument xmlDocument)
        {
            _document = (XmlDocument)xmlDocument.Clone();
            _document.PreserveWhitespace = true;

            CreateEnvelopedDocument();
        }
开发者ID:zinkpad,项目名称:FirmaXadesNet45,代码行数:11,代码来源:FirmaXades.cs

示例11: ConvertFtToMeter

            //the idea is, it searches through the document and finds items to switch out
            //it is called when needed by a user or programmer
            public XmlDocument ConvertFtToMeter(XmlDocument origdoc, XmlNamespaceManager gbXMLns1)
            {
                //number of feet in a meter
                double convrate = 3.280839895;

                XmlDocument retdoc = (XmlDocument)origdoc.Clone();
                //by default, I will always change these nodes because they are the minimum that must be presented


                //surface polyloop
                //surface lower left hand corner
                //building storeys
                XmlNodeList nodes = retdoc.SelectNodes("/gbXMLv5:gbXML/gbXMLv5:Campus/gbXMLv5:Building/gbXMLv5:BuildingStorey", gbXMLns1);
                if (nodes.Count > 0)
                {
                    foreach (XmlNode Node in nodes)
                    {
                        XmlNodeList childnodes = Node.ChildNodes;
                        foreach (XmlNode childnode in childnodes)
                        {
                            if (childnode.Name == "Level")
                            {
                                childnode.Value = Convert.ToString(Convert.ToDouble(childnode.Value) / convrate);
                            }
                            else if (childnode.Name == "PlanarGeometry")
                            {
                                //change the planar geometry
                                foreach (XmlNode PolyLoops in childnode)
                                {
                                    //gathers all the cartesian points in a given polyloop
                                    foreach (XmlNode cartesianPoints in PolyLoops)
                                    {
                                        foreach (XmlNode coordinate in cartesianPoints)
                                        {
                                            if (coordinate.Name == "Coordinate")
                                            {
                                                coordinate.Value = Convert.ToString(Convert.ToDouble(coordinate.Value) / convrate);
                                            }
                                            else
                                            {
                                                //this is bad, should terminate somehow
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //space planar geometry
                //space shell geometry
                //space space boundaries
                XmlNodeList spacenodes = retdoc.SelectNodes("/gbXMLv5:gbXML/gbXMLv5:Campus/gbXMLv5:Building/gbXMLv5:Spaces", gbXMLns1);
                if (nodes.Count > 0)
                {
                    foreach (XmlNode Node in nodes)
                    {
                        XmlNodeList childnodes = Node.ChildNodes;
                        foreach (XmlNode childnode in childnodes)
                        {
                            if (childnode.Name == "PlanarGeometry")
                            {
                                //change the planar geometry
                                foreach (XmlNode PolyLoops in childnode)
                                {
                                    //gathers all the cartesian points in a given polyloop
                                    foreach (XmlNode cartesianPoints in PolyLoops)
                                    {
                                        foreach (XmlNode coordinate in cartesianPoints)
                                        {
                                            if (coordinate.Name == "Coordinate")
                                            {
                                                coordinate.Value = Convert.ToString(Convert.ToDouble(coordinate.Value) / convrate);
                                            }
                                            else
                                            {
                                                //this is bad, should terminate somehow
                                            }
                                        }
                                    }
                                }
                            }
                            else if (childnode.Name == "ShellGeometry")
                            {
                                //this should always be the ClosedShell element
                                XmlNode closedShell = childnode.FirstChild;
                                foreach (XmlNode PolyLoops in childnode)
                                {
                                    //gathers all the cartesian points in a given polyloop
                                    foreach (XmlNode cartesianPoints in PolyLoops)
                                    {
                                        foreach (XmlNode coordinate in cartesianPoints)
                                        {
                                            if (coordinate.Name == "Coordinate")
                                            {
                                                coordinate.Value = Convert.ToString(Convert.ToDouble(coordinate.Value) / convrate);
                                            }
                                            else
//.........这里部分代码省略.........
开发者ID:chiensiTB,项目名称:ValidatorPhase1,代码行数:101,代码来源:DOEgbXMLBasics.cs

示例12: frmICOMSEditConfig_Load

        /// <summary>
        /// loading config file on form load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmICOMSEditConfig_Load(object sender, EventArgs e)
        {
            logger.Info("ICOMSEditConfiguration::frmICOMSEditConfig_Load() called");
            try
            {
                xmlDoc_ICOMS_Curr = new XmlDocument();

                // --* path to load config file from exe path *--
              //  cnfgFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + ConfigurationManager.AppSettings["ICOMSXMLFILEPATH"];
               // cnfgFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + ConfigurationManager.AppSettings["ICOMSXMLFILEPATH"];
                // --* path to load config file from developemt exe path *--

               cnfgFilePath = "../../" + ConfigurationManager.AppSettings["ICOMSXMLFILEPATH"];

                xmlDoc_ICOMS_Curr.Load(cnfgFilePath);   //load the XMl file
                logger.Info(cnfgFilePath);
                xmlDoc_ICOMS_Def = (XmlDocument)xmlDoc_ICOMS_Curr.Clone();
                loadICOMSConfiguration(xmlDoc_ICOMS_Curr);
                isDirtyChanged = false;

            }
            catch (Exception ex)
            {
                logger.Error(string.Format("frmICOMSEditConfig_Load(): Err Msg: {0}", ex.Message));
                logger.Error(string.Format("frmICOMSEditConfig_Load(): Stack Trace: {0}", ex.StackTrace));
                logger.Error("ICOMSEditConfiguration::frmICOMSEditConfig_Load() throwing error");
            }
        }
开发者ID:hari316,项目名称:Projects,代码行数:33,代码来源:frmICOMSEditConfig.cs

示例13: LoadNotes

        /// <summary>
        /// The load notes.
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        private void LoadNotes(string path)
        {
            // Объявляем и забиваем файл в XML-документ
            var xd = new XmlDocument();
            using (var fs = new FileStream(path, FileMode.Open))
            {
                xd.Load(fs);
                curDoc = null;
                curDoc = (XmlDocument)xd.Clone();
            }

            FileName = Path.GetFileNameWithoutExtension(path); // сохраняем имя прочтенного файла
        }
开发者ID:intervals-mining-lab,项目名称:libiada-core,代码行数:19,代码来源:MusicXmlReader.cs

示例14: GetAllProcessRuns

        public IXPathNavigable GetAllProcessRuns(int processId, ProcessType processType) {

            DataTable subComponents = this.m_model.GetChildComponents(processId);

            XmlDocument doc = new XmlDocument();
            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", String.Empty);
            doc.AppendChild(declaration);

            String rootName = String.Empty;
            String runName = String.Empty;
            switch (processType) {
                case ProcessType.OPTIMIZATION:
                    rootName = "Optimization";
                    runName = "OptRun";
                    break;
                case ProcessType.SIMULATION:
                    rootName = "Simulation";
                    runName = "SimRun";
                    break;
                default:
                    throw new Exception("The Process Type is not defined in the ProcessControllType enum");
            }

            XmlElement root = doc.CreateElement(rootName);
            root.SetAttribute("id", processId.ToString());
            doc.AppendChild(root);

            int id;
            String name;
            DataTable parameters;
            XmlElement runNode;
            foreach (DataRow simRunRows in subComponents.Rows) {
                id = (int)simRunRows[SchemaConstants.Id];
                runNode = doc.CreateElement(runName);
                runNode.SetAttribute("id", id.ToString());

                name = simRunRows[SchemaConstants.Name].ToString();
                runNode.SetAttribute("name", name);
                root.AppendChild(runNode);

                parameters = this.m_model.GetParameterTable(id, eParamParentType.Component.ToString());
                XmlElement parameterNode;
                String parameterId, parameterName, parameterValue;
                foreach (DataRow parameterRows in parameters.Rows) {
                    parameterId = parameterRows[SchemaConstants.Id].ToString();
                    parameterName = parameterRows[SchemaConstants.Name].ToString();
                    parameterValue = parameterRows[SchemaConstants.Value].ToString();
                    parameterNode = doc.CreateElement("Parameter");
                    parameterNode.SetAttribute("name", parameterName);
                    parameterNode.SetAttribute("value", parameterValue);
                    runNode.AppendChild(parameterNode);
                }
            }

            return doc.Clone();
        }
开发者ID:wshanshan,项目名称:DDD,代码行数:56,代码来源:AssessmentController.cs

示例15: ApplyTransform

		private Stream ApplyTransform (Transform t, XmlDocument input) 
		{
			// These transformer modify input document, which should
			// not affect to the input itself.
			if (t is XmlDsigXPathTransform 
				|| t is XmlDsigEnvelopedSignatureTransform
				|| t is XmlDecryptionTransform
			)
				input = (XmlDocument) input.Clone ();

			t.LoadInput (input);

			if (t is XmlDsigEnvelopedSignatureTransform)
				// It returns XmlDocument for XmlDocument input.
				return CanonicalizeOutput (t.GetOutput ());

			object obj = t.GetOutput ();
			if (obj is Stream)
				return (Stream) obj;
			else if (obj is XmlDocument) {
				MemoryStream ms = new MemoryStream ();
				XmlTextWriter xtw = new XmlTextWriter (ms, Encoding.UTF8);
				((XmlDocument) obj).WriteTo (xtw);

				xtw.Flush ();

				// Rewind to the start of the stream
				ms.Position = 0;
				return ms;
			}
			else if (obj == null) {
				throw new NotImplementedException ("This should not occur. Transform is " + t + ".");
			}
			else {
				// e.g. XmlDsigXPathTransform returns XmlNodeList
				return CanonicalizeOutput (obj);
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:38,代码来源:SignedXml.cs


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