protected virtual XmlDocument CreateStub_OpfDocument()
        {
            XmlDocument document = new XmlDocument();

            document.XmlResolver = null;

            document.CreateXmlDeclaration("1.0", "utf-8", null);
            document.AppendChild(document.CreateDocumentType("package",
                                                             "+//ISBN 0-9673008-1-9//DTD OEB 1.2 Package//EN",
                                                             "http://openebook.org/dtds/oeb-1.2/oebpkg12.dtd",
                                                             null));

            XmlNode rootNode = document.CreateElement(null,
                                                      "package",
                                                      "http://openebook.org/namespaces/oeb-package/1.0/");

            document.AppendChild(rootNode);


            XmlDocumentHelper.CreateAppendXmlAttribute(document, rootNode, "unique-identifier", "uid");

            XmlNode metadataNode = document.CreateElement(null, "metadata", rootNode.NamespaceURI);

            rootNode.AppendChild(metadataNode);

            XmlNode dcMetadataNode = document.CreateElement(null, "dc-metadata", rootNode.NamespaceURI);

            metadataNode.AppendChild(dcMetadataNode);
            XmlDocumentHelper.CreateAppendXmlAttribute(document, dcMetadataNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DC, DiagramContentModelHelper.NS_URL_DC);
            XmlDocumentHelper.CreateAppendXmlAttribute(document, dcMetadataNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":oebpackage", "http://openebook.org/namespaces/oeb-package/1.0/");

            XmlNode xMetadataNode = document.CreateElement(null, "x-metadata", rootNode.NamespaceURI);

            metadataNode.AppendChild(xMetadataNode);

            XmlNode manifestNode = document.CreateElement(null, "manifest", rootNode.NamespaceURI);

            rootNode.AppendChild(manifestNode);

            XmlNode spineNode = document.CreateElement(null, "spine", rootNode.NamespaceURI);

            rootNode.AppendChild(spineNode);


            return(document);
        }
Example #2
0
        public void ExportToXML(string aFile)
        {
            XmlDocument lXMLDoc = new XmlDocument();

            lXMLDoc.AppendChild(lXMLDoc.CreateXmlDeclaration("1.0", "utf-8", ""));
            lXMLDoc.AppendChild(lXMLDoc.CreateDocumentType("ReportCollection", null, null, null));
            XmlNode      lRootNode = lXMLDoc.CreateNode("element", "report-collection", "");
            XmlAttribute lDocVer   = lXMLDoc.CreateAttribute("version");

            lDocVer.Value = "rcf0";
            lRootNode.Attributes.Append(lDocVer);

            lXMLDoc.AppendChild(lRootNode);
            RootFolder.BuildXML(lRootNode, lXMLDoc);

            lXMLDoc.Save(aFile);
        }
        private void btnConectar_Click(object sender, EventArgs e)
        {
            XmlDocument myDocument = new XmlDocument();

            if (Directory.Exists(Environment.CurrentDirectory.ToString()))
            {
                if (File.Exists(Environment.CurrentDirectory.ToString() + @"\conexao.xml"))
                {
                    myDocument.Load(Environment.CurrentDirectory.ToString() + @"\conexao.xml");
                }
                else
                {
                    myDocument.CreateDocumentType(Environment.CurrentDirectory.ToString() + @"\conexao.xml", null, null, null);
                }
            }

            XmlNode node = myDocument.DocumentElement;

            foreach (XmlNode node1 in node)
            {
                foreach (XmlNode node2 in node1)
                {
                    if (node2.Name.Equals("Servidor"))
                    {
                        node2.InnerText = txtServidor.Text;
                    }
                    else if (node2.Name.Equals("Banco"))
                    {
                        node2.InnerText = txtBanco.Text;
                    }
                    else if (node2.Name.Equals("Usuario"))
                    {
                        node2.InnerText = txtUsuario.Text;
                    }
                    else if (node2.Name.Equals("Senha"))
                    {
                        node2.InnerText = txtSenha.Text;
                    }
                }
            }

            myDocument.Save(Environment.CurrentDirectory.ToString() + @"\conexao.xml");
            clsMensagem.Informacao("Informações salvas com sucesso. Para que as alterações tenham efeito você precisa finalizar a aplicação e entrar novamente!");
            Application.Exit();
        }
Example #4
0
        private void InitializeDatabase()
        {
            XmlDocument    doc = new XmlDocument();
            XmlDeclaration xmlDeclaration;

            xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
            XmlElement root = doc.DocumentElement;

            doc.InsertBefore(xmlDeclaration, root);
            XmlDocumentType doctype;

            doctype = doc.CreateDocumentType("people", null, null, INNER_DTD);
            doc.AppendChild(doctype);
            XmlElement peopleElement = doc.CreateElement(("people"));

            doc.AppendChild(peopleElement);
            doc.Save(_databasePath);
        }
Example #5
0
        public static XmlDocument CreateEntryXmlDocument()
        {
            XmlDocument xmlDoc      = new XmlDocument();
            var         declaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

            xmlDoc.AppendChild(declaration);
            var docType = xmlDoc.CreateDocumentType("Entries", null, null,
                                                    "<!ELEMENT Entries  (Entry*)>" +
                                                    "<!ELEMENT Entry (Name, UserName, Url, Password)>" +
                                                    "<!ELEMENT Name    (#PCDATA)>" +
                                                    "<!ELEMENT UserName    (#PCDATA)>" +
                                                    "<!ELEMENT Url    (#PCDATA)>" +
                                                    "<!ELEMENT Password (#PCDATA)>");

            xmlDoc.AppendChild(docType);
            xmlDoc.AppendChild(xmlDoc.CreateElement("Entries"));
            return(xmlDoc);
        }
Example #6
0
        public static XmlDocument XslExportTransform(XmlDocument doc)
        {
            StringWriter sw = new StringWriter();
            XmlWriter    xw = XmlWriter.Create(sw);

            Registry.GladeExportXsl.Transform(doc, xw);
            XmlReader reader = XmlReader.Create(sw.ToString());

            doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            doc.Load(reader);

            XmlDocumentType doctype = doc.CreateDocumentType("glade-interface", null, Glade20SystemId, null);

            doc.PrependChild(doctype);

            return(doc);
        }
Example #7
0
    //PUSH自動ON
    // https://teratail.com/questions/52234
    // http://blog.livedoor.jp/abars/archives/52394874.html
    private static void CreateEntitlements(string path, string yourappname, PBXProject pj, string target, bool prodmode)
    {
        XmlDocument     document = new XmlDocument();
        XmlDocumentType doctype  = document.CreateDocumentType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);

        document.AppendChild(doctype);

        XmlElement plist = document.CreateElement("plist");

        plist.SetAttribute("version", "1.0");
        XmlElement dict = document.CreateElement("dict");

        plist.AppendChild(dict);
        document.AppendChild(plist);

        XmlElement e = (XmlElement)document.SelectSingleNode("/plist/dict");

        XmlElement key = document.CreateElement("key");

        key.InnerText = "aps-environment";
        e.AppendChild(key);

        XmlElement value = document.CreateElement("string");

        if (prodmode == true)
        {
            value.InnerText = "production";
        }
        else
        {
            value.InnerText = "development";
        }
        e.AppendChild(value);

        string entilementions   = yourappname + ".entitlements";
        string entitlementsPath = path + "/" + entilementions;

        document.Save(entitlementsPath);

        string guid = pj.AddFile(entitlementsPath, entilementions);

        pj.SetBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", entilementions);
        pj.AddFileToBuild(target, guid);
    }
Example #8
0
        /// <summary>
        /// Get a string that contains a complete SVG document.  XML version, DOCTYPE etc are included.
        /// </summary>
        /// <returns></returns>
        /// <param name="compressAttributes">Should usually be set true.  Causes the XML output to be optimized so that
        /// long attributes like styles and transformations are represented with entities.</param>
        public string WriteSVGString(bool compressAttributes)
        {
            string s;
            string ents = "";

            XmlDocument doc = new XmlDocument();

            var declaration = doc.CreateXmlDeclaration("1.0", null, "yes");

            doc.AppendChild(declaration);

            //write out our SVG tree to the new XmlDocument
            WriteXmlElements(doc, null);

            doc.DocumentElement.SetAttribute("xmlns", "http://www.w3.org/2000/svg");

            if (compressAttributes)
            {
                ents = SvgFactory.CompressXML(doc, doc.DocumentElement);
            }

            doc.XmlResolver = new DummyXmlResolver();
            doc.InsertAfter(
                doc.CreateDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", ents),
                declaration
                );

            //This complicated business of writing to a memory stream and then reading back out to a string
            //is necessary in order to specify UTF8 -- for some reason the default is UTF16 (which makes most renderers
            //give up)

            MemoryStream  ms = new MemoryStream();
            XmlTextWriter wr = new XmlTextWriter(ms, new UTF8Encoding());

            wr.Formatting = Formatting.None;             // Indented formatting would be nice for debugging but causes unwanted trailing white spaces between <text> and <tspan> elements in Internet Explorer
            doc.Save(wr);

            byte[] buf = ms.ToArray();
            s = Encoding.UTF8.GetString(buf, 0, buf.Length);

            wr.Close();

            return(s);
        }
Example #9
0
        public XmlDocument CreateNCCStubDocument()
        {
            XmlDocument nccDocument = new XmlDocument();

            nccDocument.XmlResolver = null;

            nccDocument.CreateXmlDeclaration("1.0", "utf-8", null);
            nccDocument.AppendChild(nccDocument.CreateDocumentType("html",
                                                                   "-//W3C//DTD XHTML 1.0 Transitional//EN",
                                                                   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
                                                                   null));

            XmlNode htmlNode = nccDocument.CreateElement(null,
                                                         "html",
                                                         "http://www.w3.org/1999/xhtml");

            nccDocument.AppendChild(htmlNode);


            XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, htmlNode, "lang", "en");
            XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, htmlNode, "xml:lang", "en");


            XmlNode headNode = nccDocument.CreateElement(null, "head", htmlNode.NamespaceURI);

            htmlNode.AppendChild(headNode);
            XmlNode bodyNode = nccDocument.CreateElement(null, "body", htmlNode.NamespaceURI);

            htmlNode.AppendChild(bodyNode);

            // add css file
            string cssFileName = CreateCSSFile();

            if (cssFileName != null)
            {
                XmlNode linkNode = nccDocument.CreateElement("link", headNode.NamespaceURI);
                XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, linkNode, "rel", "stylesheet");
                XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, linkNode, "type", "text/css");
                XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, linkNode, "href", cssFileName);
                headNode.AppendChild(linkNode);
            }

            return(nccDocument);
        }
Example #10
0
        protected override void AppendDoctypeToDocument(string name, string publicIdentifier, string systemIdentifier)
        {
            // TODO: this method was not there originally. is it correct?
            document.XmlResolver = null;

            if (publicIdentifier == String.Empty)
            {
                publicIdentifier = null;
            }
            if (systemIdentifier == String.Empty)
            {
                systemIdentifier = null;
            }

            var doctype = document.CreateDocumentType(name, publicIdentifier, systemIdentifier, null);

            document.XmlResolver = new XmlUrlResolver();
            document.AppendChild(doctype);
        }
Example #11
0
        void CreateXmlFile()
        {
            XmlDocument docXml = new XmlDocument();

            //Création du noeud de déclaration xml
            XmlDeclaration declarationXml = docXml.CreateXmlDeclaration("1.0", "utf-8", null); //Version 1.0 au format utf-8

            //Création du Doctype du fichier pour pouvoir utiliser la fonciton get By ID
            XmlDocumentType Doctype = docXml.CreateDocumentType("Tasks", null, null, "<!ELEMENT Tasks ANY> <!ELEMENT Task ANY> <!ATTLIST Task ID ID #REQUIRED>");

            docXml.AppendChild(declarationXml);
            docXml.AppendChild(Doctype);
            //création du noeud Volunteers (Racine)
            XmlElement Root = docXml.CreateElement("Tasks");

            docXml.AppendChild(Root);

            docXml.Save("BaseDeDoneeTaches.xml");
        }
Example #12
0
        protected static void ReGenerateSchema(XmlDocument xmlDoc)
        {
            string dtd = DocumentType.GenerateXmlDocumentType();

            // remove current doctype
            XmlNode n = xmlDoc.FirstChild;

            while (n.NodeType != XmlNodeType.DocumentType && n.NextSibling != null)
            {
                n = n.NextSibling;
            }
            if (n.NodeType == XmlNodeType.DocumentType)
            {
                xmlDoc.RemoveChild(n);
            }
            XmlDocumentType docType = xmlDoc.CreateDocumentType("root", null, null, dtd);

            xmlDoc.InsertAfter(docType, xmlDoc.FirstChild);
        }
Example #13
0
        public static void Test(string filepath, int stake, int limit)
        {
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.AppendChild(xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", ""));

            xmldoc.AppendChild(xmldoc.CreateDocumentType("met", "-//GNU Backgammon//DTD Match Equity Tables//EN", "met.dtd", null));

            XmlElement root = xmldoc.CreateElement("met");

            xmldoc.AppendChild(root);

            XmlElement info = xmldoc.CreateElement("info");

            info.AppendChild(xmldoc.CreateElement("name"));
            info.LastChild.AppendChild(xmldoc.CreateTextNode("GRLib"));
            info.AppendChild(xmldoc.CreateElement("description"));
            info.LastChild.AppendChild(xmldoc.CreateTextNode("Stake: " + stake + " Limit: " + limit + " (in cents) rakeless table stakes MET."));
            info.AppendChild(xmldoc.CreateElement("length"));
            info.LastChild.AppendChild(xmldoc.CreateTextNode(""));//max_points.ToString()));

            root.AppendChild(info);

            // pre-crawford
            XmlElement pre = xmldoc.CreateElement("pre-crawford-table");

            pre.SetAttribute("type", "explicit");

            root.AppendChild(pre);

            // post-crawford
            XmlElement post = xmldoc.CreateElement("post-crawford-table");

            post.SetAttribute("type", "explicit");
            post.SetAttribute("player", "both");

            //double[] values = new double[max_points];
            //post.AppendChild(CreateMETRow(xml, values));

            root.AppendChild(post);

            xmldoc.Save(filepath);
        }
    public static void Main()
    {
        //Create the XmlDocument.
        XmlDocument doc = new XmlDocument();

        //Create a document type node and
        //add it to the document.
        XmlDocumentType doctype;

        doctype = doc.CreateDocumentType("book", null, null, "<!ELEMENT book ANY>");
        doc.AppendChild(doctype);

        //Create the root element and
        //add it to the document.
        doc.AppendChild(doc.CreateElement("book"));

        Console.WriteLine("Display the modified XML...");
        doc.Save(Console.Out);
    }
 public static bool SavePlistToFile(String xmlFile, Hashtable plist)
 {
     // If the hashtable is null, then there's apparently an issue; fail out.
     if (plist == null) {
         Debug.LogError("Passed a null plist hashtable to SavePlistToFile.");
         return false;
     }
     // Create the base xml document that we will use to write the data
     XmlDocument xml = new XmlDocument();
     xml.XmlResolver = null; //Disable schema/DTD validation, it's not implemented for Unity.
     // Create the root XML declaration
     // This, and the DOCTYPE, below, are standard parts of a XML property list file
     XmlDeclaration xmldecl = xml.CreateXmlDeclaration("1.0", "UTF-8", null);
     xml.PrependChild(xmldecl);
     // Create the DOCTYPE
     XmlDocumentType doctype = xml.CreateDocumentType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
     xml.AppendChild(doctype);
     // Create the root plist node, with a version number attribute.
     // Every plist file has this as the root element.  We're using version 1.0 of the plist scheme
     XmlNode plistNode = xml.CreateNode(XmlNodeType.Element, "plist", null);
     XmlAttribute plistVers = (XmlAttribute)xml.CreateNode(XmlNodeType.Attribute, "version", null);
     plistVers.Value = "1.0";
     plistNode.Attributes.Append(plistVers);
     xml.AppendChild(plistNode);
     // Now that we've created the base for the XML file, we can add all of our information to it.
     // Pass the plist data and the root dict node to SaveDictToPlistNode, which will write the plist data to the dict node.
     // This function will itterate through the hashtable hierarchy and call itself recursively for child hashtables.
     if (!SaveDictToPlistNode(plistNode, plist)) {
         // If for some reason we failed, post an error and return false.
         Debug.LogError("Failed to save plist data to root dict node: " + plist);
         return false;
     } else { // We were successful
         // Create a StreamWriter and write the XML file to disk.
         // (do not append and UTF-8 are default, but we're defining it explicitly just in case)
         StreamWriter sw = new StreamWriter(xmlFile, false, System.Text.Encoding.UTF8);
         xml.Save(sw);
         sw.Close();
     }
     // We're done here.  If there were any failures, they would have returned false.
     // Return true to indicate success.
     return true;
 }
Example #16
0
 private void InitConfigXml()
 {
     ConfigXml = new XmlDocument();
     XmlDeclaration decl = ConfigXml.CreateXmlDeclaration("1.0", "GBK", "yes");
     ConfigXml.AppendChild(decl);
     XmlDocumentType doctype = ConfigXml.CreateDocumentType("root", null, null, "<!ELEMENT Station ANY><!ATTLIST Station SSN ID #REQUIRED>");
     ConfigXml.AppendChild(doctype);
     RootNode = ConfigXml.CreateElement("MapConfig");
     ConfigXml.AppendChild(RootNode);
     XmlNode node = ConfigXml.CreateElement("Map");
     RootNode.AppendChild(node);
     node = ConfigXml.CreateElement("Divs");
     RootNode.AppendChild(node);
     node = ConfigXml.CreateElement("Statics");
     RootNode.AppendChild(node);
     node = ConfigXml.CreateElement("Stations");
     RootNode.AppendChild(node);
     node = ConfigXml.CreateElement("Words");
     RootNode.AppendChild(node);
 }
Example #17
0
    public static bool SavePlistToFile(String xmlFile, Hashtable plist)
    {
        if (plist == null)
        {
            Debug.LogError("Passed a null plist hashtable to SavePlistToFile.");
            return(false);
        }

        XmlDocument xml = new XmlDocument();

        xml.XmlResolver = null;

        XmlDeclaration xmldecl = xml.CreateXmlDeclaration("1.0", "UTF-8", null);

        xml.PrependChild(xmldecl);

        XmlDocumentType doctype = xml.CreateDocumentType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);

        xml.AppendChild(doctype);

        XmlNode      plistNode = xml.CreateNode(XmlNodeType.Element, "plist", null);
        XmlAttribute plistVers = (XmlAttribute)xml.CreateNode(XmlNodeType.Attribute, "version", null);

        plistVers.Value = "1.0";
        plistNode.Attributes.Append(plistVers);
        xml.AppendChild(plistNode);

        if (!SaveDictToPlistNode(plistNode, plist))
        {
            Debug.LogError("Failed to save plist data to root dict node: " + plist);
            return(false);
        }
        else             // We were successful
        {
            StreamWriter sw = new StreamWriter(xmlFile, false, System.Text.Encoding.UTF8);
            xml.Save(sw);
            sw.Close();
        }

        return(true);
    }
Example #18
0
        private XmlDocumentType LoadDocumentTypeNode()
        {
            Debug.Assert(_reader.NodeType == XmlNodeType.DocumentType);

            String publicId       = null;
            String systemId       = null;
            String internalSubset = _reader.Value;
            String localName      = _reader.LocalName;

            while (_reader.MoveToNextAttribute())
            {
                switch (_reader.Name)
                {
                case "PUBLIC":
                    publicId = _reader.Value;
                    break;

                case "SYSTEM":
                    systemId = _reader.Value;
                    break;
                }
            }

            XmlDocumentType dtNode = _doc.CreateDocumentType(localName, publicId, systemId, internalSubset);

            IDtdInfo dtdInfo = _reader.DtdInfo;

            if (dtdInfo != null)
            {
                LoadDocumentType(dtdInfo, dtNode);
            }
            else
            {
                //construct our own XmlValidatingReader to parse the DocumentType node so we could get Entities and notations information
                ParseDocumentType(dtNode);
            }

            return(dtNode);
        }
Example #19
0
        internal static string SearchesToXML(List <Search> searches)
        {
            XmlDocument document = new XmlDocument();

            document.XmlResolver = new BasicXMLResolver();

            document.AppendChild(document.CreateXmlDeclaration("1.0", Encoding.UTF8.WebName, null));
            document.AppendChild(document.CreateDocumentType(Search.BrandedSearchKey, "-//" + Search.BrandedSearchKey.ToUpper() + "//DTD " + Search.BrandedSearchKey.ToUpper() + " 1//EN", Search.BrandedSearchKey + "-1.dtd", null));

            XmlNode node = document.CreateElement("Searches");

            AddAttribute(document, node, "xmlns", xmlns);
            document.AppendChild(node);

            foreach (Search s in searches)
            {
                node.AppendChild(SearchToXMLNode(document, s));
            }

            StringWriter  sw = new StringWriter();
            XmlTextWriter w  = new XmlTextWriter(sw);

            try
            {
                w.Formatting  = Formatting.Indented;
                w.Indentation = 4;
                w.IndentChar  = ' ';

                document.WriteTo(w);
                w.Flush();

                return(sw.ToString());
            }
            finally
            {
                w.Close();
                sw.Close();
            }
        }
Example #20
0
        public static XmlDocument Create(string noteFolder)
        {
            var xml         = new XmlDocument();
            var declaration = xml.CreateXmlDeclaration("1.0", "UTF-8", null);

            xml.AppendChild(declaration);
            var documentType = xml.CreateDocumentType("en-export", null,
                                                      "http://xml.evernote.com/pub/evernote-export2.dtd", null);

            xml.InsertBefore(documentType, xml.DocumentElement);
            var enExport = xml.CreateElement("en-export");
            var date     = GetTimeString(DateTime.Now);

            enExport.SetAttribute("export-date", date);
            enExport.SetAttribute("application", "QOwnNotesToEnex");
            enExport.SetAttribute("version", "1.0");
            var notes = Note.Read(noteFolder);

            AddTags(noteFolder, notes, xml, enExport);
            xml.AppendChild(enExport);
            return(xml);
        }
Example #21
0
        public XmlDocument CreateDocument()
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                Uri             uri = new Uri(comboDtdUrl.Text);
                XmlDocumentType dtd = doc.CreateDocumentType(comboRootElement.Text, null, uri.AbsoluteUri, null);
                doc.AppendChild(dtd);
            }
            catch (Exception e)
            {
                MessageBox.Show(this, "An error occurred reading the DTD\n" + e.Message, "Create Document", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            XmlElement root = doc.CreateElement(comboRootElement.Text);

            doc.AppendChild(root);

            return(doc);
        }
Example #22
0
        private void ParseResources(XmlDocument xmlDocument,
                                    EnexParagraphExtension paragraphExtension, XmlNode note)
        {
            var resources = _media.Concat(_attachments);

            foreach (var fileName in resources)
            {
                var resource = xmlDocument.CreateElement("resource");
                var data     = xmlDocument.CreateElement("data");
                data.SetAttribute("encoding", "base64");
                data.InnerText = Convert.ToBase64String(File.ReadAllBytes(fileName));
                resource.AppendChild(data);
                var mime     = xmlDocument.CreateElement("mime");
                var mimeType = MimeTypesMap.GetMimeType(fileName);
                mime.InnerText = mimeType;
                resource.AppendChild(mime);
                var recognition     = xmlDocument.CreateElement("recognition");
                var recognitionDoc  = new XmlDocument();
                var recognitionDecl = recognitionDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
                recognitionDoc.AppendChild(recognitionDecl);
                var recognitionDocType = recognitionDoc.CreateDocumentType("recoIndex", "SYSTEM",
                                                                           "http://xml.evernote.com/pub/recoIndex.dtd", null);
                recognitionDoc.AppendChild(recognitionDocType);
                var recoIndex = recognitionDoc.CreateElement("recoIndex");
                recoIndex.SetAttribute("objType", mimeType);
                var hash = paragraphExtension.FindHash(fileName);
                recoIndex.SetAttribute("objID", hash);
                recognitionDoc.AppendChild(recoIndex);
                var recognitionCdata = xmlDocument.CreateCDataSection(recognitionDoc.OuterXml);
                recognition.AppendChild(recognitionCdata);
                resource.AppendChild(recognition);
                var resourceAttributes = xmlDocument.CreateElement("resource-attributes");
                var resourceFileName   = xmlDocument.CreateElement("file-name");
                resourceFileName.InnerText = Path.GetFileName(fileName);
                resourceAttributes.AppendChild(resourceFileName);
                resource.AppendChild(resourceAttributes);
                note.AppendChild(resource);
            }
        }
Example #23
0
        //public void Save(string filepath, XmlReader reader)
        static void Save(string filepath, string sType, string Base64Str)
        {
            //if (this.EDT.Equals("EDTXML"))
            if (sType.Equals("EDTXML"))
            {
                XmlDocument doc = new XmlDocument();
                doc.PreserveWhitespace = true;
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.XmlResolver   = null;
                settings.DtdProcessing = DtdProcessing.Ignore;

                XmlReader reader = XmlReader.Create(new MemoryStream(Convert.FromBase64String(Base64Str)), settings);

                doc.Load(reader);

                if (doc.DocumentType != null)
                {
                    //Replace the SystemID by the full path to the DTD on the server filesystem
                    //Similar to webclient UI checkbox 'Alter DTD System ID location' in the ouput format definition
                    XmlDocument fixdoc = new XmlDocument();
                    fixdoc.PreserveWhitespace = true;
                    fixdoc.CreateXmlDeclaration("1.0", "UTF-8", string.Empty);
                    //fixdoc.AppendChild(fixdoc.CreateDocumentType(doc.DocumentElement.Name, doc.DocumentType.PublicId, reader.GetUrn(doc.DocumentType.PublicId), null));
                    fixdoc.AppendChild(fixdoc.CreateDocumentType(doc.DocumentElement.Name, doc.DocumentType.PublicId, "", null));
                    fixdoc.AppendChild(fixdoc.ImportNode(doc.SelectSingleNode("processing-instruction()"), false));
                    fixdoc.AppendChild(fixdoc.ImportNode(doc.DocumentElement, true));
                    fixdoc.Save(filepath);
                }
                else
                {
                    doc.Save(filepath);
                }
            }
            else
            {
                File.WriteAllBytes(filepath, Convert.FromBase64String(Base64Str));
            }
        }
Example #24
0
 // Test the properties of an XmlDocumentType node.
 public void TestXmlDocumentTypeProperties()
 {
     CheckProperties("Properties (1)",
                     doc.CreateDocumentType
                         ("foo", null, null, null),
                     "foo", null, null, null,
                     "<!DOCTYPE foo>");
     CheckProperties("Properties (2)",
                     doc.CreateDocumentType
                         ("foo", "pubid", "", null),
                     "foo", "pubid", "", null,
                     "<!DOCTYPE foo PUBLIC \"pubid\" \"\">");
     CheckProperties("Properties (3)",
                     doc.CreateDocumentType
                         ("foo", "pubid&\"", "sysid", null),
                     "foo", "pubid&\"", "sysid", null,
                     "<!DOCTYPE foo PUBLIC \"pubid&amp;&quot;\" " +
                     "\"sysid\">");
     CheckProperties("Properties (4)",
                     doc.CreateDocumentType
                         ("foo", null, "sysid", null),
                     "foo", null, "sysid", null,
                     "<!DOCTYPE foo SYSTEM \"sysid\">");
     CheckProperties("Properties (5)",
                     doc.CreateDocumentType
                         ("foo", null, null, "internal"),
                     "foo", null, null, "internal",
                     "<!DOCTYPE foo [internal]>");
     CheckProperties("Properties (6)",
                     doc.CreateDocumentType
                         ("foo", null, null, "internal&\""),
                     "foo", null, null, "internal&\"",
                     "<!DOCTYPE foo [internal&\"]>");
     CheckProperties("Properties (7)",
                     doc.CreateDocumentType
                         ("foo", "pubid", "sysid", "internal"),
                     "foo", "pubid", "sysid", "internal",
                     "<!DOCTYPE foo PUBLIC \"pubid\" " +
                     "\"sysid\" [internal]>");
 }
Example #25
0
        protected XmlDocument CreateStub_NcxDocument()
        {
            XmlDocument NcxDocument = new XmlDocument();

            NcxDocument.XmlResolver = null;

            NcxDocument.CreateXmlDeclaration("1.0", "utf-8", null);
            NcxDocument.AppendChild(NcxDocument.CreateDocumentType("ncx",
                                                                   "-//NISO//DTD ncx 2005-1//EN",
                                                                   "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd",
                                                                   null));

            XmlNode rootNode = NcxDocument.CreateElement(null,
                                                         "ncx",
                                                         "http://www.daisy.org/z3986/2005/ncx/");

            NcxDocument.AppendChild(rootNode);


            XmlDocumentHelper.CreateAppendXmlAttribute(NcxDocument, rootNode, "version", "2005-1");
            XmlDocumentHelper.CreateAppendXmlAttribute(NcxDocument, rootNode,
                                                       XmlReaderWriterHelper.XmlLang,
                                                       (string.IsNullOrEmpty(m_Presentation.Language)
                ? "en-US"
                : m_Presentation.Language));


            XmlNode headNode = NcxDocument.CreateElement(null, "head", rootNode.NamespaceURI);

            rootNode.AppendChild(headNode);

            XmlNode navMapNode = NcxDocument.CreateElement(null, "navMap", rootNode.NamespaceURI);

            rootNode.AppendChild(navMapNode);

            return(NcxDocument);
        }
Example #26
0
        public static void Create()
        {
            var doc            = new XmlDocument();
            var xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
            var root           = doc.DocumentElement;

            doc.InsertBefore(xmlDeclaration, root);

            var docType = doc.CreateDocumentType("plist", "-//Apple//DTD PLIST 1.0//EN",
                                                 "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);

            doc.AppendChild(docType);

            var rootNode = doc.CreateElement("plist");

            var xmlns = doc.CreateAttribute("version");

            xmlns.Value = "1.0";
            rootNode.Attributes.Append(xmlns);

            rootNode.AppendChild(doc.CreateElement("dict"));
            doc.AppendChild(rootNode);
            doc.Save("tmp/Entitlements-merged.entitlements");
        }
Example #27
0
        /// <summary>
        /// Creates a reader to read and validate the xml data for the
        /// property element specified
        /// </summary>
        /// <param name="propertyElement">The xml property element</param>
        private void CreateValidatingReader(XmlElement propertyElement)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(propertyElement.OuterXml);
            if (doc.DocumentElement != null)
            {
                doc.InsertBefore(
                    doc.CreateDocumentType(doc.DocumentElement.Name, null, null, GetDTD(doc.DocumentElement.Name)),
                    doc.DocumentElement);
            }
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.CheckCharacters         = true;
            settings.ConformanceLevel        = ConformanceLevel.Auto;
            settings.IgnoreComments          = true;
            settings.IgnoreWhitespace        = true;
            settings.ValidationType          = ValidationType.DTD;
            settings.ValidationEventHandler += ValidationHandler;
            _reader = XmlReader.Create(new XmlTextReader(new StringReader(doc.OuterXml)), settings);


            _reader.Read();
        }
Example #28
0
        private static bool UpdateInfoPlistFromMod(string modPath, string pathToBuiltProject)
        {
            //Debug.Log ("Updating manifest from mod: " + modPath);
            bool result = true;

            var outputFile = Path.Combine(pathToBuiltProject, "Info.plist");

            if (!File.Exists(outputFile))
            {
                Debug.LogError(outputFile + " must exists before hand !");
                return(false);
            }

            XmlDocument main = new XmlDocument();

            main.Load(outputFile);

            XmlDocument mod = new XmlDocument();

            mod.Load(modPath);

            if (main == null)
            {
                Debug.LogError("Couldn't load " + outputFile);
                return(false);
            }

            if (mod == null)
            {
                Debug.LogError("Couldn't load " + modPath);
                return(false);
            }


            XmlNode mainManNode = FindChildNodeWithChildrens(main, "plist");
            XmlNode modManNode  = FindChildNodeWithChildrens(mod, "plist");

            if (mainManNode == null)
            {
                Debug.LogError("No plist tag at  " + outputFile);
                return(false);
            }

            if (modManNode == null)
            {
                Debug.LogError("No plist tag at " + modPath);
                return(false);
            }



            UpdateInfoPlistRecursivly(mainManNode, modManNode);

            //UpdateAndroidManifestNodesOrder(mainManNode);

            // Fixing the empty array at the end of the.
            // <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"[]>
            // Courtesy of Jared J.

            if (main.DocumentType != null)
            {
                var name     = main.DocumentType.Name;
                var publicId = main.DocumentType.PublicId;
                var systemId = main.DocumentType.SystemId;
                var parent   = main.DocumentType.ParentNode;
                var documentTypeWithNullInternalSubset = main.CreateDocumentType(name, publicId, systemId, null);
                parent.ReplaceChild(documentTypeWithNullInternalSubset, main.DocumentType);
            }

            main.Save(outputFile);
            return(result);
        }
        public static bool writeAnimation(string filename, Animation animation)
        {
            bool            dataSaved      = false;
            XmlDocument     doc            = doc = new XmlDocument();
            XmlDeclaration  declaration    = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
            XmlDocumentType typeDescriptor = doc.CreateDocumentType("animation", "SYSTEM", "animation.dtd", null);

            doc.AppendChild(declaration);
            doc.AppendChild(typeDescriptor);
            XmlElement mainNode = doc.CreateElement("animation");

            //mainNode.AppendChild(doc.createAttribute("id").setNodeValue(animation.getId()));
            mainNode.SetAttribute("id", animation.getId());
            mainNode.SetAttribute("usetransitions", animation.isUseTransitions() ? "yes" : "no");
            mainNode.SetAttribute("slides", animation.isSlides() ? "yes" : "no");
            XmlElement documentation = doc.CreateElement("documentation");

            if (animation.getDocumentation() != null && animation.getDocumentation().Length > 0)
            {
                documentation.InnerText = animation.getDocumentation();
            }
            mainNode.AppendChild(documentation);

            foreach (ResourcesUni resources in animation.getResources())
            {
                XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_ANIMATION);
                doc.ImportNode(resourcesNode, true);
                mainNode.AppendChild(resourcesNode);
            }

            for (int i = 0; i < animation.getFrames().Count; i++)
            {
                mainNode.AppendChild(createTransitionElement(animation.getTransitions()[i], doc));
                mainNode.AppendChild(createFrameElement(animation.getFrames()[i], doc));
            }
            mainNode.AppendChild(createTransitionElement(animation.getEndTransition(), doc));

            doc.ImportNode(mainNode, true);
            doc.AppendChild(mainNode);
            string name = "Assets/Resources/CurrentGame/" + filename;

            if (!name.EndsWith(".eaa"))
            {
                name += ".eaa";
            }
            doc.Save(name);
            System.IO.File.Copy(name, name.Substring(0, name.LastIndexOf(".")) + ".xml", true);
            //TODO: implementation?
            //transformer = tf.newTransformer();
            //transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "animation.dtd");

            //try
            //{
            //    fout = new FileOutputStream(filename);
            //}
            //catch (FileNotFoundException e)
            //{
            //    fout = new FileOutputStream(Controller.getInstance().getProjectFolder() + "/" + filename);
            //}

            //writeFile = new OutputStreamWriter(fout, "UTF-8");
            //transformer.transform(new DOMSource(doc), new StreamResult(writeFile));
            //writeFile.close();
            //fout.close();

            dataSaved = true;

            return(dataSaved);
        }
Example #30
0
        /// <inheritdoc />
        public override void Apply(XmlDocument document, string key)
        {
            // Set the evaluation context
            context["key"] = key;

            XPathExpression xpath = pathExpression.Clone();

            xpath.SetContext(context);

            // Evaluate the path
            string path = document.CreateNavigator().Evaluate(xpath).ToString();

            if (basePath != null)
            {
                path = Path.Combine(basePath, path);
            }

            string targetDirectory = Path.GetDirectoryName(path);

            if (!Directory.Exists(targetDirectory))
            {
                Directory.CreateDirectory(targetDirectory);
            }

            if (writeXhtmlNamespace)
            {
                document.DocumentElement.SetAttribute("xmlns", "http://www.w3.org/1999/xhtml");
                document.LoadXml(document.OuterXml);
            }

            if (settings.OutputMethod == XmlOutputMethod.Html)
            {
                XmlDocumentType documentType = document.CreateDocumentType("html", null, null, null);
                if (document.DocumentType != null)
                {
                    document.ReplaceChild(documentType, document.DocumentType);
                }
                else
                {
                    document.InsertBefore(documentType, document.FirstChild);
                }
            }

            // Save the document.

            // selectExpression determines which nodes get saved. If there is no selectExpression we simply
            // save the root node as before. If there is a selectExpression, we evaluate the XPath expression
            // and save the resulting node set. The select expression also enables the "literal-text" processing
            // instruction, which outputs its content as unescaped text.
            if (selectExpression == null)
            {
                try
                {
                    using (XmlWriter writer = XmlWriter.Create(path, settings))
                    {
                        document.Save(writer);
                    }
                }
                catch (IOException e)
                {
                    base.WriteMessage(key, MessageLevel.Error, "An access error occurred while attempting to " +
                                      "save to the file '{0}'. The error message is: {1}", path, e.GetExceptionMessage());
                }
                catch (XmlException e)
                {
                    base.WriteMessage(key, MessageLevel.Error, "Invalid XML was written to the output " +
                                      "file '{0}'. The error message is: '{1}'", path, e.GetExceptionMessage());
                }
            }
            else
            {
                // IMPLEMENTATION NOTE: The separate StreamWriter is used to maintain XML indenting.  Without it
                // the XmlWriter won't honor our indent settings after plain text nodes have been written.
                using (StreamWriter output = File.CreateText(path))
                {
                    using (XmlWriter writer = XmlWriter.Create(output, settings))
                    {
                        XPathExpression select_xpath = selectExpression.Clone();
                        select_xpath.SetContext(context);

                        XPathNodeIterator ni = document.CreateNavigator().Select(selectExpression);

                        while (ni.MoveNext())
                        {
                            if (ni.Current.NodeType == XPathNodeType.ProcessingInstruction &&
                                ni.Current.Name.Equals("literal-text"))
                            {
                                writer.Flush();
                                output.Write(ni.Current.Value);
                            }
                            else
                            {
                                ni.Current.WriteSubtree(writer);
                            }
                        }
                    }
                }
            }

            // Raise an event to indicate that a file was created
            this.OnComponentEvent(new FileCreatedEventArgs(path, true));
        }
Example #31
0
        public static int CreateMoneyGameMET(string filename, double stake, double limit, bool rake)
        {
            int max_points = (int)(limit / stake);            //Game.MaxPoints(stake, limit);

            if (max_points * stake < limit)
            {
                max_points++;
            }
            if (max_points < 1)
            {
                max_points = 1;
            }

            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.AppendChild(xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", ""));

                xmldoc.AppendChild(xmldoc.CreateDocumentType("met", "-//GNU Backgammon//DTD Match Equity Tables//EN",
                                                             "met\\" + "met.dtd", null));

                //root element
                XmlElement root = xmldoc.CreateElement("met");
                xmldoc.AppendChild(root);

                //info element
                XmlElement info = xmldoc.CreateElement("info");

                info.AppendChild(xmldoc.CreateElement("name"));
                info.LastChild.AppendChild(xmldoc.CreateTextNode("Munkittajat ry"));
                info.AppendChild(xmldoc.CreateElement("description"));
                info.LastChild.AppendChild(xmldoc.CreateTextNode("How to own the PartyGammon cash games"));
                info.AppendChild(xmldoc.CreateElement("length"));
                info.LastChild.AppendChild(xmldoc.CreateTextNode(max_points.ToString()));

                root.AppendChild(info);



                // pre-crawford

                XmlElement pre = xmldoc.CreateElement("pre-crawford-table");
                pre.SetAttribute("type", "explicit");


                // hero win
                double[] hero_values = new double[max_points];
                //	for (int i = 0; i < hero_values.Length; i++) hero_values[i] = -1000;

                for (int i = max_points - 1; i >= 1; i--)
                {
                    hero_values[hero_values.Length - 1] = METValue(stake, limit, true, i);

                    pre.AppendChild(CreateMETRow(xmldoc, hero_values));
                }

                // opponent win
                double[] opponent_values = new double[max_points];
                //	for (int i = 0; i < opponent_values.Length; i++) opponent_values[i] = -1000;

                for (int i = 0; i < max_points; i++)
                {
                    opponent_values[i] = METValue(stake, limit, false, max_points - 1 - i);
                }

                pre.AppendChild(CreateMETRow(xmldoc, opponent_values));


                root.AppendChild(pre);



                // post-crawford

                XmlElement post = xmldoc.CreateElement("post-crawford-table");
                post.SetAttribute("type", "explicit");
                post.SetAttribute("player", "both");

                double[] values = new double[max_points];
                //	for (int i=0; i<values.Length; i++) values[i]=-1000;
                post.AppendChild(CreateMETRow(xmldoc, values));

                root.AppendChild(post);



                xmldoc.Save("met//" + filename);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(max_points);
        }
	// Test adding an XML declaration to the document.
	public void TestXmlDocumentAddXmlDeclaration()
			{
				XmlDocument doc = new XmlDocument();

				// Add the declaration.
				XmlDeclaration decl =
					doc.CreateXmlDeclaration("1.0", null, null);
				AssertNull("XmlDeclaration (1)", decl.ParentNode);
				AssertEquals("XmlDeclaration (2)", doc, decl.OwnerDocument);
				doc.AppendChild(decl);
				AssertEquals("XmlDeclaration (3)", doc, decl.ParentNode);
				AssertEquals("XmlDeclaration (4)", doc, decl.OwnerDocument);

				// Try to add it again, which should fail this time.
				try
				{
					doc.AppendChild(decl);
					Fail("adding XmlDeclaration node twice");
				}
				catch(InvalidOperationException)
				{
					// Success
				}
				try
				{
					doc.PrependChild(decl);
					Fail("prepending XmlDeclaration node twice");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding a document type before should fail.
				XmlDocumentType type =
					doc.CreateDocumentType("foo", null, null, null);
				try
				{
					doc.PrependChild(type);
					Fail("prepending XmlDocumentType");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding a document type after should succeed.
				doc.AppendChild(type);

				// Adding an element before should fail.
				XmlElement element = doc.CreateElement("foo");
				try
				{
					doc.PrependChild(element);
					Fail("prepending XmlElement");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding the element between decl and type should fail.
				try
				{
					doc.InsertAfter(element, decl);
					Fail("inserting XmlElement between XmlDeclaration " +
						 "and XmlDocumentType");
				}
				catch(InvalidOperationException)
				{
					// Success
				}
				try
				{
					doc.InsertBefore(element, type);
					Fail("inserting XmlElement between XmlDeclaration " +
						 "and XmlDocumentType (2)");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding an element after should succeed.
				doc.AppendChild(element);
			}
	// Test adding an element to the document.
	public void TestXmlDocumentAddElement()
			{
				XmlDocument doc = new XmlDocument();

				// Add an element to the document.
				XmlElement element = doc.CreateElement("foo");
				AssertNull("XmlElement (1)", element.ParentNode);
				AssertEquals("XmlElement (2)", doc, element.OwnerDocument);
				doc.AppendChild(element);
				AssertEquals("XmlElement (3)", doc, element.ParentNode);
				AssertEquals("XmlElement (4)", doc, element.OwnerDocument);

				// Try to add it again, which should fail this time.
				try
				{
					doc.AppendChild(element);
					Fail("adding XmlElement node twice");
				}
				catch(InvalidOperationException)
				{
					// Success
				}
				try
				{
					doc.PrependChild(element);
					Fail("prepending XmlElement node twice");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding an XmlDeclaration after should fail.
				XmlDeclaration decl =
					doc.CreateXmlDeclaration("1.0", null, null);
				try
				{
					doc.AppendChild(decl);
					Fail("appending XmlDeclaration after XmlElement");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// But adding XmlDeclaration before should succeed.
				doc.PrependChild(decl);

				// Adding a document type after should fail.
				XmlDocumentType type =
					doc.CreateDocumentType("foo", null, null, null);
				try
				{
					doc.AppendChild(type);
					Fail("appending XmlDocumentType");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding a document type before should succeed.
				doc.InsertBefore(type, element);
			}
    public static void PostProcessBuild(BuildTarget target, string pathToBuiltProject)
    {
        #if UNITY_4_6 || UNITY_4_5
        if (target != BuildTarget.iPhone)
        #else
        if (target != BuildTarget.iOS)
        #endif
        {
            return;
        }

        Debug.Log("[Seeds] Going to post-process project in '" + pathToBuiltProject + "'");

        var projectPath = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));

        var seedsSettingsXml = new XmlDocument();
        var seedsSettingsFilename = Path.Combine(Application.dataPath, "../ProjectSettings/SeedsSDK.xml");
        if (File.Exists(seedsSettingsFilename))
            seedsSettingsXml.Load(seedsSettingsFilename);

        var deepLinkingNode = seedsSettingsXml.SelectSingleNode("SeedsSDK/iOS/DeepLinking");

        var scheme = "";
        var pathPrefix = "";
        var host = "";
        if (deepLinkingNode != null)
        {
            var schemeAttribute = deepLinkingNode.Attributes.GetNamedItem("scheme");
            if (schemeAttribute != null)
                scheme = schemeAttribute.Value;

            var hostAttribute = deepLinkingNode.Attributes.GetNamedItem("host");
            if (hostAttribute != null)
                host = hostAttribute.Value;

            var pathPrefixAttribute = deepLinkingNode.Attributes.GetNamedItem("pathPrefix");
            if (pathPrefixAttribute != null)
                pathPrefix = pathPrefixAttribute.Value;
        }

        // Write SeedsConfig.h
        #if UNITY_5
        var seedsConfigPathInProject = "Libraries/Plugins/iOS";
        #elif UNITY_4_6 || UNITY_4_5
        var seedsConfigPathInProject = "Libraries";
        #else
        #error Unsupported Unity3D version, please contact support.
        #endif
        var seedsConfigFilename = Path.Combine(pathToBuiltProject, Path.Combine(seedsConfigPathInProject, "SeedsConfig.h"));
        using (var seedsConfigFile = File.Open(seedsConfigFilename, FileMode.Create))
        {
            using (var seedsConfig = new StreamWriter(seedsConfigFile))
            {
                seedsConfig.WriteLine("// DeepLinking");
                seedsConfig.WriteLine("#define SEEDS_DeepLinking_scheme @\"{0}\"", scheme);
                seedsConfig.WriteLine("#define SEEDS_DeepLinking_host @\"{0}\"", host);
                seedsConfig.WriteLine("#define SEEDS_DeepLinking_pathPrefix @\"{0}\"", pathPrefix);
            }
        }

        // Convert "Unity-iPhone.xcodeproj/project.pbxproj" to xml1 format using plutil
        System.Diagnostics.Process
            .Start(new System.Diagnostics.ProcessStartInfo("plutil")
            {
                Arguments = "-convert xml1 \"Unity-iPhone.xcodeproj/project.pbxproj\"",
                UseShellExecute = true,
                WorkingDirectory = pathToBuiltProject
            })
            .WaitForExit();

        // Read pbxproj as XML
        var pbxprojFilename = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj/project.pbxproj");
        var pbxproj = new XmlDocument();
        pbxproj.Load(pbxprojFilename);
        var objectsNode = pbxproj.SelectSingleNode("/plist/dict/key[text()=\"objects\"]/following-sibling::*[1]");
        var targetNode = pbxproj.SelectSingleNode(
             "//dict[" +
             "key[text()=\"isa\"]/following-sibling::*[1]/text()=\"PBXNativeTarget\" and " +
             "key[text()=\"name\"]/following-sibling::*[1]/text()=\"Unity-iPhone\"" +
             "]");

        #if UNITY_4_6 || UNITY_4_5
        // Copy SeedsResources.bundle
        var seedsResourcesPathInAssets = "Assets/Plugins/iOS/SeedsResources.bundle/";
        var seedsResources = AssetDatabase.GetAllAssetPaths()
            .Where(x => x.StartsWith(seedsResourcesPathInAssets))
            .ToList();
        var seedsResourcesPathInProject = "Libraries/SeedsResources.bundle";
        var seedsResourcesPath = Path.Combine(pathToBuiltProject, seedsResourcesPathInProject);
        Directory.CreateDirectory(seedsResourcesPath);
        foreach (var seedsResourcePath in seedsResources)
        {
            var srcPath = Path.Combine(projectPath, seedsResourcePath);
            var dstPath = Path.Combine(seedsResourcesPath, seedsResourcePath.Replace(seedsResourcesPathInAssets, ""));
            var attributes = File.GetAttributes(srcPath);

            if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
                Directory.CreateDirectory(dstPath);
            else if (!File.Exists(dstPath))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(dstPath));
                File.Copy(srcPath, dstPath);
            }
        }

        // Add SeedsResources.bundle to the project
        var seedsResourcesFileRefKey = GeneratePbxprojKey(pbxproj);
        objectsNode.AppendChildElement("key", seedsResourcesFileRefKey);
        var seedsResourcesFileRefNode = objectsNode.AppendChildElement("dict");
        seedsResourcesFileRefNode.AppendChildElement("key", "isa");
        seedsResourcesFileRefNode.AppendChildElement("string", "PBXFileReference");
        seedsResourcesFileRefNode.AppendChildElement("key", "lastKnownFileType");
        seedsResourcesFileRefNode.AppendChildElement("string", "wrapper.plug-in");
        seedsResourcesFileRefNode.AppendChildElement("key", "name");
        seedsResourcesFileRefNode.AppendChildElement("string", "SeedsResources.bundle");
        seedsResourcesFileRefNode.AppendChildElement("key", "path");
        seedsResourcesFileRefNode.AppendChildElement("string", seedsResourcesPathInProject);
        seedsResourcesFileRefNode.AppendChildElement("key", "sourceTree");
        seedsResourcesFileRefNode.AppendChildElement("string", "SOURCE_ROOT");

        var seedsResourcesBuildFileKey = GeneratePbxprojKey(pbxproj);
        objectsNode.AppendChildElement("key", seedsResourcesBuildFileKey);
        var seedsResourcesBuildFileNode = objectsNode.AppendChildElement("dict");
        seedsResourcesBuildFileNode.AppendChildElement("key", "fileRef");
        seedsResourcesBuildFileNode.AppendChildElement("string", seedsResourcesFileRefKey);
        seedsResourcesBuildFileNode.AppendChildElement("key", "isa");
        seedsResourcesBuildFileNode.AppendChildElement("string", "PBXBuildFile");

        var librariesGroupChildrenNode = pbxproj.SelectSingleNode(
            "//dict[" +
            "key[text()=\"isa\"]/following-sibling::*[1]/text()=\"PBXGroup\" and " +
            "key[text()=\"path\"]/following-sibling::*[1]/text()=\"Libraries\"" +
            "]/key[text()=\"children\"]/following-sibling::*[1]");
        librariesGroupChildrenNode.AppendChildElement("string", seedsResourcesFileRefKey);

        AddFileReferenceToBuildPhase(pbxproj, "PBXResourcesBuildPhase", seedsResourcesBuildFileKey);
        #endif

        // Add missing system frameworks
        AddSystemFramework(pbxproj, "CoreData");
        AddSystemFramework(pbxproj, "CoreTelephony");

        // Tweak build configurations
        var buildConfigurationListKey = targetNode
            .SelectSingleNode("key[text()=\"buildConfigurationList\"]/following-sibling::*[1]/text()")
            .Value;
        var buildConfigurationListNode = objectsNode.SelectSingleNode(
            string.Format("key[text()=\"{0}\"]/following-sibling::*[1]", buildConfigurationListKey));
        var buildConfigurationList =
            buildConfigurationListNode.SelectNodes("key[text()=\"buildConfigurations\"]/following-sibling::*[1]/string/text()");
        foreach (XmlNode buildConfigurationListEntry in buildConfigurationList)
        {
            var buildConfigurationKey = buildConfigurationListEntry.Value;
            var buildConfigurationNode = objectsNode.SelectSingleNode(
                string.Format("key[text()=\"{0}\"]/following-sibling::*[1]", buildConfigurationKey));

            var buildSettings =
                buildConfigurationNode.SelectSingleNode("key[text()=\"buildSettings\"]/following-sibling::*[1]");

            var otherLinkerFlagsNode = buildSettings.SelectSingleNode("key[text()=\"OTHER_LDFLAGS\"]/following-sibling::*[1]");
            if (otherLinkerFlagsNode == null)
            {
                buildSettings.AppendChildElement("key", "OTHER_LDFLAGS");
                otherLinkerFlagsNode = buildSettings.AppendChildElement("array");
            }

            // Add -ObjC flag to linker flags of the target
            var objCFlagNode = otherLinkerFlagsNode.SelectSingleNode("string[text()=\"-ObjC\"]");
            if (objCFlagNode == null)
                objCFlagNode = otherLinkerFlagsNode.AppendChildElement("string", "-ObjC");

            // Tweak Info.plist file to support deep-linking
            var infoPlistFilename =
                buildSettings.SelectSingleNode("key[text()=\"INFOPLIST_FILE\"]/following-sibling::*[1]/text()").Value;
            var infoPlistPath = Path.Combine(pathToBuiltProject, infoPlistFilename);
            var infoPlist = new XmlDocument();
            infoPlist.Load(infoPlistPath);

            var infoPlistContent = infoPlist.SelectSingleNode("plist/dict");
            var urlTypesNode = infoPlistContent.SelectSingleNode("key[text()=\"CFBundleURLTypes\"]/following-sibling::*[1]");
            if (urlTypesNode == null)
            {
                infoPlistContent.AppendChildElement("key", "CFBundleURLTypes");
                urlTypesNode = infoPlistContent.AppendChildElement("array");
            }

            var urlSchemeEntryNode = urlTypesNode.SelectSingleNode("dict[string=\"com.playseeds.unity3d.${PRODUCT_NAME}\"]");
            if (urlSchemeEntryNode == null)
            {
                urlSchemeEntryNode = urlTypesNode.AppendChildElement("dict");

                urlSchemeEntryNode.AppendChildElement("key", "CFBundleURLName");
                urlSchemeEntryNode.AppendChildElement("string", "com.playseeds.unity3d.${PRODUCT_NAME}");
            }

            var urlSchemeNode =
                urlSchemeEntryNode.SelectSingleNode("key[text()=\"CFBundleURLSchemes\"]//following-sibling::*[1]");
            if (urlSchemeNode == null)
            {
                urlSchemeEntryNode.AppendChildElement("key", "CFBundleURLSchemes");
                urlSchemeNode = urlSchemeEntryNode.AppendChildElement("array");
            }

            urlSchemeNode.RemoveAll();
            urlSchemeNode.AppendChildElement("string", scheme);

            if (infoPlist.DocumentType != null)
            {
                var name = infoPlist.DocumentType.Name;
                var publicId = infoPlist.DocumentType.PublicId;
                var systemId = infoPlist.DocumentType.SystemId;
                var parent = infoPlist.DocumentType.ParentNode;
                var documentTypeWithNullInternalSubset = infoPlist.CreateDocumentType(name, publicId, systemId, null);
                parent.ReplaceChild(documentTypeWithNullInternalSubset, infoPlist.DocumentType);
            }

            infoPlist.Save(infoPlistPath);
        }

        // Save pbxproj as XML and fix it
        var xmlWriterSettings = new XmlWriterSettings
        {
            Indent = false,
            NewLineHandling = NewLineHandling.None
        };
        using (var xmlWriter = XmlWriter.Create(pbxprojFilename, xmlWriterSettings))
        {
            pbxproj.Save(xmlWriter);
        }
        var pbxprojContent = File.ReadAllText(pbxprojFilename);
        pbxprojContent = pbxprojContent
            .Replace(
                "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"[]>",
                "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
        File.WriteAllText(pbxprojFilename, pbxprojContent);
    }