CreateProcessingInstruction() public method

public CreateProcessingInstruction ( String target, String data ) : XmlProcessingInstruction
target String
data String
return XmlProcessingInstruction
Beispiel #1
1
        //ArrayList openElements = new ArrayList();
        public void SerializeXml(IList<StarSystem> starSystems)
        {
            MemoryStream memXmlStream = new MemoryStream();
            XmlSerializer serializer = new XmlSerializer(starSystems.GetType(), null, new Type[] { typeof(Planet), typeof(StarSystem) }, new XmlRootAttribute("Stars"), null, null);

            serializer.Serialize(memXmlStream, starSystems);

            XmlDocument xmlDoc = new XmlDocument();

            memXmlStream.Seek(0, SeekOrigin.Begin);
            xmlDoc.Load(memXmlStream);

            XmlProcessingInstruction newPI;
            String PItext = string.Format("type='text/xsl' href='{0}'", "system.xslt");
            newPI = xmlDoc.CreateProcessingInstruction("xml-stylesheet", PItext);

            xmlDoc.InsertAfter(newPI, xmlDoc.FirstChild);

            // Now write the document

            // out to the final output stream

            XmlTextWriter wr = new XmlTextWriter("system.xml", System.Text.Encoding.ASCII);
            wr.Formatting = Formatting.Indented;
            wr.IndentChar = '\t';
            wr.Indentation = 1;

            XmlWriterSettings settings = new XmlWriterSettings();
            XmlWriter writer = XmlWriter.Create(wr, settings);

            xmlDoc.WriteTo(writer);
            writer.Flush();
            //Console.Write(xmlDoc.InnerXml);
        }
Beispiel #2
0
        public static string ConvertFromPHP(string sPHP)
        {
            XmlDocument xml = new XmlDocument();
            xml.AppendChild(xml.CreateProcessingInstruction("xml" , "version=\"1.0\" encoding=\"UTF-8\""));
            xml.AppendChild(xml.CreateElement("USER_PREFERENCE"));
            try
            {
                byte[] abyPHP = Convert.FromBase64String(sPHP);
                StringBuilder sb = new StringBuilder();
                foreach(char by in abyPHP)
                    sb.Append(by);
                MemoryStream mem = new MemoryStream(abyPHP);

                string sSize = String.Empty;
                int nChar = mem.ReadByte();
                while ( nChar != -1 )
                {
                    char ch = Convert.ToChar(nChar);
                    if ( ch == 'a' )
                        PHPArray(xml, xml.DocumentElement, mem);
                    else if ( ch == 's' )
                        PHPString(mem);
                    else if ( ch == 'i' )
                        PHPInteger(mem);
                    nChar = mem.ReadByte();
                }
            }
            catch(Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
            }
            return xml.OuterXml;
        }
Beispiel #3
0
        protected internal void MakeRoot(string namespaceURI, string rootElementName, string schemaLocation)
        {
            XmlDocument doc = new XmlDocument();
            XmlElement root = doc.CreateElement(rootElementName, namespaceURI);

            doc.AppendChild(doc.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
            doc.AppendChild(root);

            root.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            if (namespaceURI == null || namespaceURI == "")
            {
                if (schemaLocation != null && schemaLocation != "")
                {
                    XmlAttribute a = doc.CreateAttribute("xsi:noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
                    a.Value = schemaLocation;
                    root.SetAttributeNode(a);
                }
            }
            else
            {
                if (schemaLocation != null && schemaLocation != "")
                {
                    XmlAttribute a = doc.CreateAttribute("xsi:schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
                    a.Value = namespaceURI + " " + schemaLocation;
                    root.SetAttributeNode(a);
                }
            }

            foreach (XmlAttribute attribute in domNode.Attributes)
                root.Attributes.Append((XmlAttribute)doc.ImportNode(attribute, true));
            foreach (XmlNode childNode in domNode.ChildNodes)
                root.AppendChild(doc.ImportNode(childNode, true));

            domNode = root;
        }
Beispiel #4
0
		// 02/02/2010   ACT Database Import is a Professional/Enterprise feature. 
		public static XmlDocument ConvertActToXml(string sImportModule, Stream stm)
		{
			XmlDocument xml = new XmlDocument();
			xml.AppendChild(xml.CreateProcessingInstruction("xml" , "version=\"1.0\" encoding=\"UTF-8\""));
			xml.AppendChild(xml.CreateElement("xml"));
			return xml;
		}
        public void Save(string fileName)
        {
            if (this.Messages.Count == 0 || string.IsNullOrEmpty(fileName)) return;
            if (File.Exists(fileName)) File.Delete(fileName);

            var xml = new XmlDocument();
            xml.AppendChild(xml.CreateXmlDeclaration(this.Declaration.Version, this.Declaration.Encoding, this.Declaration.Standalone));
            xml.AppendChild(xml.CreateProcessingInstruction(this.Xsl.Target, this.Xsl.Data));

            var root = xml.CreateElement("Log");
            root.SetAttribute("FirstSessionID", this.Messages[0].SessionID.ToString());
            root.SetAttribute("LastSessionID", this.Messages[this.Messages.Count - 1].SessionID.ToString());

            xml.AppendChild(root);
            this.Messages.ForEach(messageNode =>
                {
                    var nodeName = messageNode.GetType().Name.Replace("Msn", string.Empty);
                    var newNode = xml.CreateElement(nodeName);
                    root.AppendChild(messageNode.GenerateXmlNode(newNode));
                });

            var writer = new XmlTextWriter(fileName, Encoding.UTF8);
            writer.WriteRaw(xml.OuterXml);
            writer.Flush();
            writer.Close();
        }
Beispiel #6
0
	public static string SaveToFile ()
	{
		string title;
		string[] fragments;
		XmlDocument doc;
		XmlElement item;
		XmlAttribute subject_attr, body_attr, contrib_attr;
		
		fragments = subject.Split (' ');
		title = null;
		foreach (string s in fragments)
		{
			title += s;
		}
		doc = new XmlDocument ();
		doc.AppendChild (doc.CreateProcessingInstruction ("xml", "version='1.0'"));
		item = doc.CreateElement ("mwnitem");
		subject_attr = doc.CreateAttribute ("subject");
		subject_attr.Value = subject;
		body_attr = doc.CreateAttribute ("body");
		body_attr.Value = @body;
		contrib_attr = doc.CreateAttribute ("contrib");
		contrib_attr.Value = @contrib;
		item.Attributes.Append (subject_attr);
		item.Attributes.Append (body_attr);
		item.Attributes.Append (contrib_attr);
		doc.AppendChild (item);
		doc.Save ((title = title.Substring (0, 8)) + ".mwnitem");
		return title;
	}
 public XmlDocument GetXml(String xslFile)
 {
     XmlDocument doc = new XmlDocument();
       XmlElement root = doc.CreateElement("licenses");
       doc.AppendChild(root);
       if (!String.IsNullOrEmpty(xslFile))
       {
     XmlNode pi = doc.CreateProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"" + xslFile + "\"");
     doc.InsertBefore(pi, root);
       }
       foreach (LicenseInfo license in _licenses.Values)
       {
     XmlElement licenseElement = doc.CreateElement("license");
     licenseElement.SetAttribute("productName", license.Product);
     licenseElement.SetAttribute("productVersion", license.Version);
     if (!String.IsNullOrEmpty(license.ParentProduct))
     {
       licenseElement.SetAttribute("parentProduct", license.ParentProduct);
     }
     if (!String.IsNullOrEmpty(license.LicenseFilename))
     {
       licenseElement.SetAttribute("filename", license.LicenseFilename);
     }
     if (!String.IsNullOrEmpty(license.LicenseType))
     {
       licenseElement.SetAttribute("licenseType", license.LicenseType);
     }
     if (!String.IsNullOrEmpty(license.Url))
     {
       licenseElement.SetAttribute("url", license.Url);
     }
     root.AppendChild(licenseElement);
       }
       return doc;
 }
        public static void BasicCreate()
        {
            var xmlDocument = new XmlDocument();
            var newNode = xmlDocument.CreateProcessingInstruction("bar", "foo");

            Assert.Equal("<?bar foo?>", newNode.OuterXml);
            Assert.Equal(XmlNodeType.ProcessingInstruction, newNode.NodeType);
        }
Beispiel #9
0
 public static XmlDocument MakeRequestDocument()
 {
     XmlDocument inputXMLDoc = null;
     inputXMLDoc = new XmlDocument();
     inputXMLDoc.AppendChild(inputXMLDoc.CreateXmlDeclaration("1.0", null, null));
     inputXMLDoc.AppendChild(inputXMLDoc.CreateProcessingInstruction("qbxml", "version=\"12.0\""));
     return inputXMLDoc;
 }
        public XmlPolicyLanguageWriter(XmlPolicyLanguageStore store)
        {
            m_languageStore = store;

            m_xmlDocument = new XmlDocument();
            XmlProcessingInstruction processingInstruction = m_xmlDocument.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
            m_xmlDocument.AppendChild(processingInstruction);
            m_xmlLanguageNode = m_xmlDocument.CreateElement("PolicySetLanguage");
            m_xmlDocument.AppendChild(m_xmlLanguageNode);
        }
Beispiel #11
0
        public static void InsertNewNodeToElement()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<a><b/></a>");
            var root = xmlDocument.DocumentElement;
            var newNode = xmlDocument.CreateProcessingInstruction("PI", "pi data");

            root.InsertBefore(newNode, root.FirstChild);

            Assert.Equal(2, root.ChildNodes.Count);
        }
 private void CreateDocument()
 {
     m_xmlDocument = new XmlDocument();
     XmlProcessingInstruction processingInstruction = m_xmlDocument.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
     m_xmlDocument.AppendChild(processingInstruction);
     m_catalogue = m_xmlDocument.CreateElement("PolicySetCatalogue");
     XmlHelpers.AddAttribute(m_catalogue, "id", m_catalogueGuid.ToString("B", CultureInfo.InvariantCulture).ToUpper(CultureInfo.InvariantCulture));
     XmlHelpers.AddAttribute(m_catalogue, "languageId", m_languageGuid.ToString("B", CultureInfo.InvariantCulture).ToUpper(CultureInfo.InvariantCulture));
     XmlHelpers.AddAttribute(m_catalogue, "name", "");
     m_xmlDocument.AppendChild(m_catalogue);
 }
Beispiel #13
0
 protected XmlNode createDocument(string rootName, string schemaLocation)
 {
     dom = new XmlDocument();
     XmlNode xmlNode = dom.CreateProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
     dom.AppendChild(xmlNode);
     XmlNode root = dom.CreateNode(XmlNodeType.Element, prefix, rootName, nameSpace);
     addStringAttribute(root, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
     XmlAttribute schema = dom.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
     schema.Value = schemaLocation;
     root.Attributes.Append(schema);
     return root;
 }
Beispiel #14
0
 public XmlDocument GetAsXml()
 {
     var doc = new XmlDocument();
     var dec = doc.CreateXmlDeclaration("1.0", null, null);
     doc.AppendChild(dec);
     var pi = doc.CreateProcessingInstruction("xml-stylesheet", @"type='text/xsl' href='FactorStatistics.xslt'");
     doc.AppendChild(pi);
     XmlElement root = doc.CreateElement("RaceAnalysis");
     doc.AppendChild(root);
     _analyzers.ForEach(analyzer => analyzer.AddToXmlDocument(doc,root));
     return doc;
 }
Beispiel #15
0
		public XmlPolicyWriter(XmlStore store)
		{
			m_store = store;

			m_xmlDocument = new XmlDocument();
			XmlProcessingInstruction processingInstruction = m_xmlDocument.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
			m_xmlDocument.AppendChild(processingInstruction);
			m_xmlRootNode = m_xmlDocument.CreateElement("PolicySetStore");
			m_xmlDocument.AppendChild(m_xmlRootNode);

			m_policieSetsNode = m_xmlDocument.CreateElement("PolicySets");
			m_xmlRootNode.AppendChild(m_policieSetsNode);
		}
Beispiel #16
0
        public static XmlDocument GetErrorDocument(string errormessage)
        {
            XmlDocument errorDoc = new XmlDocument();

            errorDoc.AppendChild(errorDoc.CreateProcessingInstruction("xml-stylesheet", "type='text/xsl' href='xsl/errorPage.xsl'"));
            XmlNode root = errorDoc.AppendChild(errorDoc.CreateNode(XmlNodeType.Element, "root", null));
            XmlNode node = root.AppendChild(errorDoc.CreateNode(XmlNodeType.Element, "message", null));

            node.InnerText = errormessage;

            Timingutil.info("Compile Error ! , generate ErrorDom");
            return errorDoc;
        }
        public XmlDocument CreateDocument()
        {
            // <?xeditnet-profile ../xenwebprofile/bin/debug/xenwebprofile.dll!XenWebProfile.ProfileImpl?>

            XmlDocument doc=new XmlDocument();
            XmlDocumentType doctype=doc.CreateDocumentType(profileInfo.Root, profileInfo.PublicId, profileInfo.SystemId, null);
            XmlElement root=doc.CreateElement(profileInfo.Root);
            XmlProcessingInstruction pi=doc.CreateProcessingInstruction("xeditnet-profile", profileInfo.Profile);

            doc.AppendChild(doctype);
            doc.AppendChild(pi);
            doc.AppendChild(root);
            return doc;
        }
        //RootItem m_view = null;
        public static void Process(RootItem view,string outPath)
        {
            //m_view = view;
            //m_view.Accept(this, null);

            XmlDocument xml = new XmlDocument();
            XmlDeclaration dec = xml.CreateXmlDeclaration("1.0", "UTF-8", null);
            xml.AppendChild(dec);
            string PItext = @"type='text/xsl' href='ReportStyle.xsl'";
            XmlProcessingInstruction newPI = xml.CreateProcessingInstruction("xml-stylesheet", PItext);
            xml.AppendChild(newPI);
            xml.AppendChild(view.ToXml(xml));
            xml.Save(outPath);
        }
        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);
        }
        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);
        }
Beispiel #21
0
    private void SetupXmlDoc()
    {
        XmlProcessingInstruction Version = null;

        //<?xml version="1.0"?>

        //Create a new document object
        MyXMLDoc = new XmlDocument();
        MyXMLDoc.PreserveWhitespace = false;
        //MyXMLDoc.async = False
        //tell the parser to automatically load externally defined DTD's or XSD's
        //MyXMLDoc.resolveExternals = True

        Version = MyXMLDoc.CreateProcessingInstruction("xml", "version=" + Strings.Chr(34) + "1.0" + Strings.Chr(34));
        //create the root element
        //and append it and the XML version to the document
        MyXMLDoc.AppendChild(Version);

        MyXMLDoc.AppendChild(MyXMLDoc.CreateElement("Alugen3"));
    }
Beispiel #22
0
        public static XmlDocument BuildCustomerQueryByWorkorderNum(string woNum)
        {
            XmlDocument doc = new XmlDocument();
            doc.AppendChild(doc.CreateXmlDeclaration("1.0", null, null));
            doc.AppendChild(doc.CreateProcessingInstruction("qbxml", "version=\"12.0\""));
            XmlElement qbXML = doc.CreateElement("QBXML");
            doc.AppendChild(qbXML);
            XmlElement qbXMLMsgsRq = doc.CreateElement("QBXMLMsgsRq");
            qbXML.AppendChild(qbXMLMsgsRq);
            qbXMLMsgsRq.SetAttribute("onError", "stopOnError");
            XmlElement custAddRq = doc.CreateElement("CustomerQueryRq");
            qbXMLMsgsRq.AppendChild(custAddRq);

            XmlElement NameFilter = doc.CreateElement("NameFilter");
            custAddRq.AppendChild(NameFilter);
            NameFilter.AppendChild(XmlUtils.MakeSimpleElem(doc, "MatchCriterion", "Contains"));
            NameFilter.AppendChild(XmlUtils.MakeSimpleElem(doc, "Name", woNum));
            custAddRq.AppendChild(XmlUtils.MakeSimpleElem(doc, "OwnerID", "0"));

            return doc;
        }
        protected string GetXml()
#endif
        {
            var doc = new XmlDocument();
            XmlProcessingInstruction xpi = doc.CreateProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            doc.AppendChild(xpi);

            XmlElement root = doc.CreateElement("WIRECARD_BXML");
            root.SetAttribute("xmlns:xsi", "http://www.w3.org/1999/XMLSchema-instance");
            doc.AppendChild(root);

            XmlElement request = doc.CreateElement("W_REQUEST");
            root.AppendChild(request);

            foreach (Job job in _jobs)
            {
                XmlElement node = job.GetXml(doc);
                request.AppendChild(node);
            }

            return doc.OuterXml;
        }
        private XmlDocument GetTableDependancyMap()
        {
            XmlDocument dependancyMap = new XmlDocument();
            dependancyMap.AppendChild(dependancyMap.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
            XmlElement rootElement = dependancyMap.CreateElement("DependancyMap");
            dependancyMap.AppendChild(rootElement);

            foreach (Table table in Database.Tables)
            {
                //* Query for the xml element, create it if it doesn't already exist
                //  NB:  this page has a lot of good Xml manipulation info: http://omegacoder.com/?p=46
                XmlElement element = (XmlElement)dependancyMap.SelectSingleNode("/DependencyMap/Table[@Name=\"" + table.Name + "\"]");

                if (element == null)
                {
                    element = dependancyMap.CreateElement("Table");
                    element.SetAttribute("Name", table.Name);
                    rootElement.AppendChild(element);
                }

                foreach (ForeignKey foreignKey in table.ForeignKeys)
                {
                    //* Add dependency
                    XmlElement dependencyElement = dependancyMap.CreateElement("Dependency");
                    dependencyElement.SetAttribute("Name", foreignKey.ReferencedTable);
                    element.AppendChild(dependencyElement);
                }
            }

            return dependancyMap;
        }
        private XmlDocument GetDependancyMap()
        {
            XmlDocument dependancyMap = new XmlDocument();
            dependancyMap.AppendChild(dependancyMap.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
            XmlElement rootElement = dependancyMap.CreateElement("DependancyMap");
            dependancyMap.AppendChild(rootElement);

            DataSet dataset = Database.ExecuteWithResults(@"
            select
            s.name as dependantSchema,
            base.name as dependantName,
            base.type as dependantType,
            d.referenced_schema_name as dependencySchema,
            d.referenced_entity_name as dependencyName,
            dependancy.type as dependancyType
            from sys.sql_expression_dependencies d
            join sys.objects base on d.referencing_id = base.[object_id]
            join sys.schemas s on base.[schema_id] = s.[schema_id]
            join sys.objects dependancy on d.referenced_id = dependancy.[object_id]
            where dependancy.type <> 'U'
            ");

            //* There should be at least 1 table...
            DataTable table = dataset.Tables[0];

            //* Loop through each row and add it to the appropriate XML element (creating it if necessary)
            foreach (DataRow row in table.Rows)
            {
                //* Extract information from row
                string dependantSchema = Convert.ToString(row["dependantSchema"]);
                string dependantName = Convert.ToString(row["dependantName"]);
                string dependantType = Convert.ToString(row["dependantType"]);
                string dependencySchema = Convert.ToString(row["dependencySchema"]);
                string dependencyName = Convert.ToString(row["dependencyName"]);
                string dependancyType = Convert.ToString(row["dependancyType"]);

                //* Query for the xml element, create it if it doesn't already exist
                //  NB:  this page has a lot of good Xml manipulation info: http://omegacoder.com/?p=46
                XmlElement element = (XmlElement)dependancyMap.SelectSingleNode("/DependencyMap/DBObject[@name=\"" + dependantName + "\"]");

                if (element == null)
                {
                    element = dependancyMap.CreateElement("DBObject");
                    element.SetAttribute("DBObjectName", dependantName);
                    element.SetAttribute("Type", dependantType);
                    rootElement.AppendChild(element);
                }

                //* Add dependency
                XmlElement dependencyElement = dependancyMap.CreateElement("Dependency");
                dependencyElement.SetAttribute("DBObjectName", dependencyName);
                dependencyElement.SetAttribute("Type", dependancyType);

                element.AppendChild(dependencyElement);
            }
            return dependancyMap;
        }
Beispiel #26
0
        // Save logged actions and expected results to an XML file
        public void Save()
        {
            // get the total time the test run
            TimeSpan elapsed_time = DateTime.Now - startTime;

            FlushBuffer ();

            XmlDocument xmlDoc = new XmlDocument ();

            //add XML declaration
            XmlNode xmlDecl = xmlDoc.CreateXmlDeclaration ("1.0", "UTF-8", "");
            xmlDoc.AppendChild (xmlDecl);
            XmlNode xmlStyleSheet = xmlDoc.CreateProcessingInstruction ("xml-stylesheet", "type=\"text/xsl\" href=\"Resources/procedures.xsl\"");
            xmlDoc.AppendChild (xmlStyleSheet);

            //add a root element
            XmlElement rootElm = xmlDoc.CreateElement ("test");
            xmlDoc.AppendChild (rootElm);

            //add <name> element
            XmlElement nameElm = xmlDoc.CreateElement ("name");
            XmlText nameElmText = xmlDoc.CreateTextNode ("KeePass");
            nameElm.AppendChild (nameElmText);
            rootElm.AppendChild (nameElm);

            //add <description> element
            XmlElement descElm = xmlDoc.CreateElement ("description");
            XmlText descElmText = xmlDoc.CreateTextNode ("Test cases for KeePass");
            descElm.AppendChild (descElmText);
            rootElm.AppendChild (descElm);

            //add <parameters> element
            XmlElement paraElm = xmlDoc.CreateElement ("parameters");
            //TODO: add if clause to determine whether add <environments> element or not.
            XmlElement envElm = xmlDoc.CreateElement ("environments");
            paraElm.AppendChild (envElm);
            rootElm.AppendChild (paraElm);

            //add <procedures> element
            XmlElement procElm = xmlDoc.CreateElement ("procedures");

            foreach (List<string> p in procedures) {
                //add <action> element in <step> element
                XmlElement stepElm = xmlDoc.CreateElement ("step");

                //add <action> element in <step> element
                XmlElement actionElm = xmlDoc.CreateElement ("action");
                XmlText actionElmText = xmlDoc.CreateTextNode (p [0]);
                actionElm.AppendChild (actionElmText);
                stepElm.AppendChild (actionElm);

                //add <expectedResult> element in <step> element
                XmlElement resultElm = xmlDoc.CreateElement ("expectedResult");
                XmlText resultElmText = xmlDoc.CreateTextNode (p [1]);
                resultElm.AppendChild (resultElmText);
                stepElm.AppendChild (resultElm);

                //add <screenshot> element in <step> element
                if (Config.Instance.TakeScreenShots) {
                    XmlElement screenshotElm = xmlDoc.CreateElement ("screenshot");
                    XmlText screenshotElmText = xmlDoc.CreateTextNode (p [2]);
                    //add if clause to determine whether has a screenshot or not.
                    screenshotElm.AppendChild (screenshotElmText);
                    stepElm.AppendChild (screenshotElm);
                }

                procElm.AppendChild (stepElm);
            }

            rootElm.AppendChild (procElm);

            //add <time> element
            XmlElement timeElm = xmlDoc.CreateElement ("time");
            XmlText timeEleText = xmlDoc.CreateTextNode (Convert.ToString (elapsed_time.TotalSeconds));
            timeElm.AppendChild (timeEleText);
            rootElm.AppendChild (timeElm);

            //write the Xml content to a xml file
            try {
                xmlDoc.Save ("procedures.xml");
            } catch (Exception e) {
                Console.WriteLine (e.Message);
            }
        }
Beispiel #27
0
        private void SaveStartupState()
        {
            try
            {
                XmlDocument xDoc = new XmlDocument();
                XmlProcessingInstruction xPI;
                xPI = xDoc.CreateProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
                xDoc.AppendChild(xPI);

                XmlNode xDS = xDoc.CreateElement("readerstate");
                xDoc.AppendChild(xDS);

                XmlNode xN;
                // Loop thru the current files
                XmlNode xFiles = xDoc.CreateElement("CurrentFiles");
                xDS.AppendChild(xFiles);
                foreach (MDIChild mc in this.MdiChildren)
                {
                    Uri file = mc.SourceFile;
                    if (file == null)
                        continue;
                    xN = xDoc.CreateElement("file");
                    xN.InnerText = file.LocalPath;
                    xFiles.AppendChild(xN);
                }

                // Loop thru recent files list
                xFiles = xDoc.CreateElement("RecentFiles");
                xDS.AppendChild(xFiles);
                foreach (string f in _RecentFiles.Values)
                {
                    xN = xDoc.CreateElement("file");
                    xN.InnerText = f;
                    xFiles.AppendChild(xN);
                }

                string optFileName = AppDomain.CurrentDomain.BaseDirectory + "readerstate.xml";

                xDoc.Save(optFileName);
            }
            catch { }		// still want to leave even on error

            return;
        }
    public void SerializeNodeTypes()
    {
      XmlDocument doc = new XmlDocument();
      string jsonText;

      Console.WriteLine("SerializeNodeTypes");

      string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<xs:schema xs:id=""SomeID"" 
	xmlns="""" 
	xmlns:xs=""http://www.w3.org/2001/XMLSchema"" 
	xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
	<xs:element name=""MyDataSet"" msdata:IsDataSet=""true"">
	</xs:element>
</xs:schema>";

      XmlDocument document = new XmlDocument();
      document.LoadXml(xml);

      // XmlAttribute
      XmlAttribute attribute = document.DocumentElement.ChildNodes[0].Attributes["IsDataSet", "urn:schemas-microsoft-com:xml-msdata"];
      attribute.Value = "true";

      jsonText = JsonConvert.SerializeXmlNode(attribute);

      Console.WriteLine(jsonText);
      Assert.AreEqual(@"{""@msdata:IsDataSet"":""true""}", jsonText);

#if !NET20
      XDocument d = XDocument.Parse(xml);
      XAttribute a = d.Root.Element("{http://www.w3.org/2001/XMLSchema}element").Attribute("{urn:schemas-microsoft-com:xml-msdata}IsDataSet");

      jsonText = JsonConvert.SerializeXNode(a);

      Assert.AreEqual(@"{""@msdata:IsDataSet"":""true""}", jsonText);
#endif

      // XmlProcessingInstruction
      XmlProcessingInstruction instruction = doc.CreateProcessingInstruction("xml-stylesheet", @"href=""classic.xsl"" type=""text/xml""");

      jsonText = JsonConvert.SerializeXmlNode(instruction);

      Console.WriteLine(jsonText);
      Assert.AreEqual(@"{""?xml-stylesheet"":""href=\""classic.xsl\"" type=\""text/xml\""""}", jsonText);


      // XmlProcessingInstruction
      XmlCDataSection cDataSection = doc.CreateCDataSection("<Kiwi>true</Kiwi>");

      jsonText = JsonConvert.SerializeXmlNode(cDataSection);

      Console.WriteLine(jsonText);
      Assert.AreEqual(@"{""#cdata-section"":""<Kiwi>true</Kiwi>""}", jsonText);


      // XmlElement
      XmlElement element = doc.CreateElement("xs", "Choice", "http://www.w3.org/2001/XMLSchema");
      element.SetAttributeNode(doc.CreateAttribute("msdata", "IsDataSet", "urn:schemas-microsoft-com:xml-msdata"));

      XmlAttribute aa = doc.CreateAttribute(@"xmlns", "xs", "http://www.w3.org/2000/xmlns/");
      aa.Value = "http://www.w3.org/2001/XMLSchema";
      element.SetAttributeNode(aa);

      aa = doc.CreateAttribute(@"xmlns", "msdata", "http://www.w3.org/2000/xmlns/");
      aa.Value = "urn:schemas-microsoft-com:xml-msdata";
      element.SetAttributeNode(aa);

      element.AppendChild(instruction);
      element.AppendChild(cDataSection);

      doc.AppendChild(element);

      jsonText = JsonConvert.SerializeXmlNode(element, Formatting.Indented);

      Assert.AreEqual(@"{
  ""xs:Choice"": {
    ""@msdata:IsDataSet"": """",
    ""@xmlns:xs"": ""http://www.w3.org/2001/XMLSchema"",
    ""@xmlns:msdata"": ""urn:schemas-microsoft-com:xml-msdata"",
    ""?xml-stylesheet"": ""href=\""classic.xsl\"" type=\""text/xml\"""",
    ""#cdata-section"": ""<Kiwi>true</Kiwi>""
  }
}", jsonText);
    }
        private void Page_Load(object sender, System.EventArgs e)
        {
            // 01/24/2006 Paul.  Only a developer/administrator should see this.
            // 01/27/2006 Paul.  Just require admin.
            if ( !SplendidCRM.Security.IS_ADMIN )
                return;
            try
            {
                DbProviderFactory dbf = DbProviderFactories.GetFactory();
                using ( IDbConnection con = dbf.CreateConnection() )
                {
                    con.Open();
                    using ( IDbCommand cmd = con.CreateCommand() )
                    {
                        using ( DbDataAdapter da = dbf.CreateDataAdapter() )
                        {
                            ((IDbDataAdapter)da).SelectCommand = cmd;
                            string sSQL;
                            string sNAME = Sql.ToString(Request.QueryString["NAME"]) ;
                            if ( Sql.IsEmptyString(sNAME) )
                            {
                                sSQL = "select *          " + ControlChars.CrLf
                                     + "  from vwEDITVIEWS" + ControlChars.CrLf
                                     + " order by NAME    " + ControlChars.CrLf;
                                cmd.CommandText = sSQL;
                                using ( SqlDataReader rdr = (SqlDataReader) cmd.ExecuteReader() )
                                {
                                    Response.Write("<html><body><h1>EditViews</h1>");
                                    while ( rdr.Read() )
                                    {
                                        Response.Write("<a href=\"EditViews.aspx?NAME=" + rdr.GetString(rdr.GetOrdinal("NAME")) + "\">" + rdr.GetString(rdr.GetOrdinal("NAME")) + "</a><br>" + ControlChars.CrLf);
                                    }
                                    Response.Write("</body></html>");
                                }
                            }
                            else
                            {
                                Response.ContentType = "text/xml";
                                Response.AddHeader("Content-Disposition", "attachment;filename=" + sNAME + ".Mapping.xml");

                                XmlDocument xml = new XmlDocument();
                                xml.AppendChild(xml.CreateProcessingInstruction("xml" , "version=\"1.0\" encoding=\"UTF-8\""));
                                xml.AppendChild(xml.CreateElement("SplendidTest.Dictionary"));
                                XmlAttribute aName = xml.CreateAttribute("Name");
                                aName.Value = sNAME + ".Mapping.xml";
                                xml.DocumentElement.Attributes.Append(aName);

                                sSQL = "select DATA_FIELD               " + ControlChars.CrLf
                                     + "     , DISPLAY_FIELD            " + ControlChars.CrLf
                                     + "  from vwEDITVIEWS_FIELDS       " + ControlChars.CrLf
                                     + " where EDIT_NAME    = @EDIT_NAME" + ControlChars.CrLf
                                     + "   and DEFAULT_VIEW = 0         " + ControlChars.CrLf
                                     + "   and DATA_FIELD is not null   " + ControlChars.CrLf
                                     + " order by FIELD_INDEX           " + ControlChars.CrLf;
                                cmd.CommandText = sSQL;
                                Sql.AddParameter(cmd, "@EDIT_NAME", sNAME);

                                using ( SqlDataReader rdr = (SqlDataReader) cmd.ExecuteReader() )
                                {
                                    while ( rdr.Read() )
                                    {
                                        string sDATA_FIELD = rdr.GetString(rdr.GetOrdinal("DATA_FIELD"));
                                        Utils.AppendDictionaryEntry(xml, sDATA_FIELD, "ctlEditView_" + sDATA_FIELD);

                                        if ( !rdr.IsDBNull(rdr.GetOrdinal("DISPLAY_FIELD")) )
                                        {
                                            string sDISPLAY_FIELD = rdr.GetString(rdr.GetOrdinal("DISPLAY_FIELD"));
                                            if ( sDATA_FIELD != sDISPLAY_FIELD )
                                                Utils.AppendDictionaryEntry(xml, sDISPLAY_FIELD, "ctlEditView_" + sDISPLAY_FIELD);
                                        }
                                    }
                                }
                                Utils.AppendDictionaryEntry(xml, "btnSave"  , "ctlEditView_ctlEditButtons_btnSave"  );
                                Utils.AppendDictionaryEntry(xml, "btnCancel", "ctlEditView_ctlEditButtons_btnCancel");

                                StringBuilder sb = new StringBuilder();
                                if ( xml != null && xml.DocumentElement != null)
                                    XmlUtil.Dump(ref sb, "", xml.DocumentElement);
                                Response.Write(sb.ToString());
                            }
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                Response.Write(ex.Message + ControlChars.CrLf);
            }
        }
Beispiel #30
0
        /// -------------------------------------------------------------------
        public XmlRiskSerializer()
        {
            _document = new XmlDocument();

            XmlProcessingInstruction procInstr =
                _document.CreateProcessingInstruction("xml", " version='1.0' encoding='UTF-8'");
///             _document.CreateProcessingInstruction("xml", " version='1.0' encoding='us-ascii'");
            _document.AppendChild(procInstr);

            _metadataNode = _document.CreateNode(XmlNodeType.Element, "Metadata", null);
            _document.AppendChild(_metadataNode);

            _documentsNode = _document.CreateNode(XmlNodeType.Element, "Documents", null);
            _metadataNode.AppendChild(_documentsNode);

            _applicationsNode = _document.CreateNode(XmlNodeType.Element, "Applications", null);
            _metadataNode.AppendChild(_applicationsNode);

            XmlNode dateTimeNode = getDateTime();
            _applicationsNode.AppendChild(dateTimeNode);

            XmlNode loggedUser = getLoggedUser();
            _applicationsNode.AppendChild(loggedUser);

            dateTimeNode = null;
            loggedUser = null;
        }
        private XmlNode LoadNode(bool skipOverWhitespace)
        {
            XmlReader      r      = this.reader;
            XmlNode        parent = null;
            XmlElement     element;
            IXmlSchemaInfo schemaInfo;

            do
            {
                XmlNode node = null;
                switch (r.NodeType)
                {
                case XmlNodeType.Element:
                    bool fEmptyElement = r.IsEmptyElement;
                    element         = doc.CreateElement(r.Prefix, r.LocalName, r.NamespaceURI);
                    element.IsEmpty = fEmptyElement;

                    if (r.MoveToFirstAttribute())
                    {
                        XmlAttributeCollection attributes = element.Attributes;
                        do
                        {
                            XmlAttribute attr = LoadAttributeNode();
                            attributes.Append(attr);       // special case for load
                        }while(r.MoveToNextAttribute());
                        r.MoveToElement();
                    }

                    // recursively load all children.
                    if (!fEmptyElement)
                    {
                        if (parent != null)
                        {
                            parent.AppendChildForLoad(element, doc);
                        }
                        parent = element;
                        continue;
                    }
                    else
                    {
                        schemaInfo = r.SchemaInfo;
                        if (schemaInfo != null)
                        {
                            element.XmlName = doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo);
                        }
                        node = element;
                        break;
                    }

                case XmlNodeType.EndElement:
                    if (parent == null)
                    {
                        return(null);
                    }
                    Debug.Assert(parent.NodeType == XmlNodeType.Element);
                    schemaInfo = r.SchemaInfo;
                    if (schemaInfo != null)
                    {
                        element = parent as XmlElement;
                        if (element != null)
                        {
                            element.XmlName = doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo);
                        }
                    }
                    if (parent.ParentNode == null)
                    {
                        return(parent);
                    }
                    parent = parent.ParentNode;
                    continue;

                case XmlNodeType.EntityReference:
                    node = LoadEntityReferenceNode(false);
                    break;

                case XmlNodeType.EndEntity:
                    Debug.Assert(parent == null);
                    return(null);

                case XmlNodeType.Attribute:
                    node = LoadAttributeNode();
                    break;

                case XmlNodeType.Text:
                    node = doc.CreateTextNode(r.Value);
                    break;

                case XmlNodeType.SignificantWhitespace:
                    node = doc.CreateSignificantWhitespace(r.Value);
                    break;

                case XmlNodeType.Whitespace:
                    if (preserveWhitespace)
                    {
                        node = doc.CreateWhitespace(r.Value);
                        break;
                    }
                    else if (parent == null && !skipOverWhitespace)
                    {
                        // if called from LoadEntityReferenceNode, just return null
                        return(null);
                    }
                    else
                    {
                        continue;
                    }

                case XmlNodeType.CDATA:
                    node = doc.CreateCDataSection(r.Value);
                    break;


                case XmlNodeType.XmlDeclaration:
                    node = LoadDeclarationNode();
                    break;

                case XmlNodeType.ProcessingInstruction:
                    node = doc.CreateProcessingInstruction(r.Name, r.Value);
                    break;

                case XmlNodeType.Comment:
                    node = doc.CreateComment(r.Value);
                    break;

                case XmlNodeType.DocumentType:
                    node = LoadDocumentTypeNode();
                    break;

                default:
                    throw UnexpectedNodeType(r.NodeType);
                }

                Debug.Assert(node != null);
                if (parent != null)
                {
                    parent.AppendChildForLoad(node, doc);
                }
                else
                {
                    return(node);
                }
            }while (r.Read());

            // when the reader ended before full subtree is read, return whatever we have created so far
            if (parent != null)
            {
                while (parent.ParentNode != null)
                {
                    parent = parent.ParentNode;
                }
            }
            return(parent);
        }
    private void DeserializeValue(JsonReader reader, XmlDocument document, XmlNamespaceManager manager, string propertyName, XmlNode currentNode)
    {
      switch (propertyName)
      {
        case TextName:
          currentNode.AppendChild(document.CreateTextNode(reader.Value.ToString()));
          break;
        case CDataName:
          currentNode.AppendChild(document.CreateCDataSection(reader.Value.ToString()));
          break;
        case WhitespaceName:
          currentNode.AppendChild(document.CreateWhitespace(reader.Value.ToString()));
          break;
        case SignificantWhitespaceName:
          currentNode.AppendChild(document.CreateSignificantWhitespace(reader.Value.ToString()));
          break;
        default:
          // processing instructions and the xml declaration start with ?
          if (!string.IsNullOrEmpty(propertyName) && propertyName[0] == '?')
          {
            if (propertyName == DeclarationName)
            {
              string version = null;
              string encoding = null;
              string standalone = null;
              while (reader.Read() && reader.TokenType != JsonToken.EndObject)
              {
                switch (reader.Value.ToString())
                {
                  case "@version":
                    reader.Read();
                    version = reader.Value.ToString();
                    break;
                  case "@encoding":
                    reader.Read();
                    encoding = reader.Value.ToString();
                    break;
                  case "@standalone":
                    reader.Read();
                    standalone = reader.Value.ToString();
                    break;
                  default:
                    throw new JsonSerializationException("Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
                }
              }

              XmlDeclaration declaration = document.CreateXmlDeclaration(version, encoding, standalone);
              currentNode.AppendChild(declaration);
            }
            else
            {
              XmlProcessingInstruction instruction = document.CreateProcessingInstruction(propertyName.Substring(1), reader.Value.ToString());
              currentNode.AppendChild(instruction);
            }
          }
          else
          {
            // deserialize xml element
            bool finishedAttributes = false;
            bool finishedElement = false;
            string elementPrefix = GetPrefix(propertyName);
            Dictionary<string, string> attributeNameValues = new Dictionary<string, string>();

            // a string token means the element only has a single text child
            if (reader.TokenType != JsonToken.String
              && reader.TokenType != JsonToken.Null
              && reader.TokenType != JsonToken.Boolean
              && reader.TokenType != JsonToken.Integer
              && reader.TokenType != JsonToken.Float
              && reader.TokenType != JsonToken.Date
              && reader.TokenType != JsonToken.StartConstructor)
            {
              // read properties until first non-attribute is encountered
              while (!finishedAttributes && !finishedElement && reader.Read())
              {
                switch (reader.TokenType)
                {
                  case JsonToken.PropertyName:
                    string attributeName = reader.Value.ToString();

                    if (attributeName[0] == '@')
                    {
                      attributeName = attributeName.Substring(1);
                      reader.Read();
                      string attributeValue = reader.Value.ToString();
                      attributeNameValues.Add(attributeName, attributeValue);

                      string namespacePrefix;

                      if (IsNamespaceAttribute(attributeName, out namespacePrefix))
                      {
                        manager.AddNamespace(namespacePrefix, attributeValue);
                      }
                    }
                    else
                    {
                      finishedAttributes = true;
                    }
                    break;
                  case JsonToken.EndObject:
                    finishedElement = true;
                    break;
                  default:
                    throw new JsonSerializationException("Unexpected JsonToken: " + reader.TokenType);
                }
              }
            }

            // have to wait until attributes have been parsed before creating element
            // attributes may contain namespace info used by the element
            XmlElement element = (!string.IsNullOrEmpty(elementPrefix))
                    ? document.CreateElement(propertyName, manager.LookupNamespace(elementPrefix))
                    : document.CreateElement(propertyName);

            currentNode.AppendChild(element);

            // add attributes to newly created element
            foreach (KeyValuePair<string, string> nameValue in attributeNameValues)
            {
              string attributePrefix = GetPrefix(nameValue.Key);

              XmlAttribute attribute = (!string.IsNullOrEmpty(attributePrefix))
                      ? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix))
                      : document.CreateAttribute(nameValue.Key);

              attribute.Value = nameValue.Value;

              element.SetAttributeNode(attribute);
            }

            if (reader.TokenType == JsonToken.String)
            {
              element.AppendChild(document.CreateTextNode(reader.Value.ToString()));
            }
            else if (reader.TokenType == JsonToken.Integer)
            {
              element.AppendChild(document.CreateTextNode(XmlConvert.ToString((long)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Float)
            {
              element.AppendChild(document.CreateTextNode(XmlConvert.ToString((double)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Boolean)
            {
              element.AppendChild(document.CreateTextNode(XmlConvert.ToString((bool)reader.Value)));
            }
            else if (reader.TokenType == JsonToken.Date)
            {
              DateTime d = (DateTime)reader.Value;
              element.AppendChild(document.CreateTextNode(XmlConvert.ToString(d, DateTimeUtils.ToSerializationMode(d.Kind))));
            }
            else if (reader.TokenType == JsonToken.Null)
            {
              // empty element. do nothing
            }
            else
            {
              // finished element will have no children to deserialize
              if (!finishedElement)
              {
                manager.PushScope();

                DeserializeNode(reader, document, manager, element);

                manager.PopScope();
              }
            }
          }
          break;
      }
    }
Beispiel #33
0
 public override void WriteProcessingInstruction(string name, string value)
 {
     WritePossiblyTopLevelNode(
         doc.CreateProcessingInstruction(name, value), false);
 }