// Check the properties on an XmlDocumentType node.
	private void CheckProperties(String msg, XmlDocumentType type,
								 String name, String publicId,
								 String systemId, String internalSubset,
								 String xml)
			{
				AssertNull(msg + " [1]", type.Attributes);
				AssertEquals(msg + " [2]", String.Empty, type.BaseURI);
				AssertNotNull(msg + " [3]", type.ChildNodes);
				AssertNull(msg + " [4]", type.FirstChild);
				Assert(msg + " [5]", !type.HasChildNodes);
				Assert(msg + " [6]", type.IsReadOnly);
				AssertEquals(msg + " [7]", name, type.LocalName);
				AssertEquals(msg + " [8]", name, type.Name);
				AssertEquals(msg + " [9]", publicId, type.PublicId);
				AssertEquals(msg + " [10]", systemId, type.SystemId);
				AssertEquals(msg + " [11]",
							 internalSubset, type.InternalSubset);
				AssertEquals(msg + " [12]", String.Empty, type.NamespaceURI);
				AssertNull(msg + " [13]", type.NextSibling);
				AssertEquals(msg + " [14]",
							 XmlNodeType.DocumentType, type.NodeType);
				AssertEquals(msg + " [15]", doc, type.OwnerDocument);
				AssertNull(msg + " [16]", type.ParentNode);
				AssertEquals(msg + " [17]", String.Empty, type.Prefix);
				AssertNull(msg + " [18]", type.PreviousSibling);
				AssertEquals(msg + " [19]", String.Empty, type.Value);
				AssertEquals(msg + " [20]", String.Empty, type.InnerXml);
				AssertEquals(msg + " [21]", xml, type.OuterXml);
			}
Пример #2
0
        internal XmlDiffNode LoadNode(XmlNode node, ref int childPosition)
        {
            switch (node.NodeType)
            {
            case XmlNodeType.Element:
                XmlDiffElement elem = new XmlDiffElement(++childPosition, node.LocalName, node.Prefix, node.NamespaceURI);
                LoadChildNodes(elem, node);
                elem.ComputeHashValue(_xmlHash);
                return(elem);

            case XmlNodeType.Attribute:
                Debug.Assert(false, "Attributes cannot be loaded by this method.");
                return(null);

            case XmlNodeType.Text:
                string          textValue = (_XmlDiff.IgnoreWhitespace) ? XmlDiff.NormalizeText(node.Value) : node.Value;
                XmlDiffCharData text      = new XmlDiffCharData(++childPosition, textValue, XmlDiffNodeType.Text);
                text.ComputeHashValue(_xmlHash);
                return(text);

            case XmlNodeType.CDATA:
                XmlDiffCharData cdata = new XmlDiffCharData(++childPosition, node.Value, XmlDiffNodeType.CDATA);
                cdata.ComputeHashValue(_xmlHash);
                return(cdata);

            case XmlNodeType.EntityReference:
                XmlDiffER er = new XmlDiffER(++childPosition, node.Name);
                er.ComputeHashValue(_xmlHash);
                return(er);

            case XmlNodeType.Comment:
                ++childPosition;
                if (_XmlDiff.IgnoreComments)
                {
                    return(null);
                }

                XmlDiffCharData comment = new XmlDiffCharData(childPosition, node.Value, XmlDiffNodeType.Comment);
                comment.ComputeHashValue(_xmlHash);
                return(comment);

            case XmlNodeType.ProcessingInstruction:
                ++childPosition;
                if (_XmlDiff.IgnorePI)
                {
                    return(null);
                }

                XmlDiffPI pi = new XmlDiffPI(childPosition, node.Name, node.Value);
                pi.ComputeHashValue(_xmlHash);
                return(pi);

            case XmlNodeType.SignificantWhitespace:
                ++childPosition;
                if (_XmlDiff.IgnoreWhitespace)
                {
                    return(null);
                }
                XmlDiffCharData ws = new XmlDiffCharData(childPosition, node.Value, XmlDiffNodeType.SignificantWhitespace);
                ws.ComputeHashValue(_xmlHash);
                return(ws);

            case XmlNodeType.XmlDeclaration:
                ++childPosition;
                if (_XmlDiff.IgnoreXmlDecl)
                {
                    return(null);
                }
                XmlDiffXmlDeclaration xmlDecl = new XmlDiffXmlDeclaration(childPosition, XmlDiff.NormalizeXmlDeclaration(node.Value));
                xmlDecl.ComputeHashValue(_xmlHash);
                return(xmlDecl);

            case XmlNodeType.EndElement:
                return(null);

            case XmlNodeType.DocumentType:
                childPosition++;
                if (_XmlDiff.IgnoreDtd)
                {
                    return(null);
                }

                XmlDocumentType     docType     = (XmlDocumentType)node;
                XmlDiffDocumentType diffDocType = new XmlDiffDocumentType(childPosition, docType.Name, docType.PublicId, docType.SystemId, docType.InternalSubset);
                diffDocType.ComputeHashValue(_xmlHash);
                return(diffDocType);

            default:
                Debug.Assert(false);
                return(null);
            }
        }
Пример #3
0
 public XmlDocumentTypeWrapper(XmlDocumentType documentType)
 {
     Class6.yDnXvgqzyB5jw();
     base(documentType);
     this._documentType = documentType;
 }
Пример #4
0
        /// <summary>
        /// Return a string representation for GetShortString that
        /// describes the "thing" that has been compared so users know
        /// how to locate it.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Examples are "&lt;bar ...&gt; at /foo[1]/bar[1]" for a
        /// comparison of elements or "&lt;!-- Comment Text --&gt; at
        /// /foo[2]/comment()[1]" for a comment.
        /// </para>
        /// <para>
        /// This implementation dispatches to several AppendX methods
        /// based on the comparison type or the type of the node.
        /// </para>
        /// </remarks>
        /// <param name="node">the node to describe</param>
        /// <param name="xpath">xpath of the node if applicable</param>
        /// <param name="type">the comparison type</param>
        /// <return>the formatted result</return>
        /// since XMLUnit 2.4.0
        protected virtual string GetShortString(XmlNode node, string xpath, ComparisonType type)
        {
            StringBuilder sb = new StringBuilder();

            if (type == ComparisonType.HAS_DOCTYPE_DECLARATION)
            {
                XmlDocument doc = node as XmlDocument;
                AppendDocumentType(sb, doc.DocumentType);
                AppendDocumentElementIndication(sb, doc);
            }
            else if (node is XmlDocument)
            {
                XmlDocument doc = node as XmlDocument;
                AppendDocumentXmlDeclaration(sb, doc.FirstChild as XmlDeclaration);
                AppendDocumentElementIndication(sb, doc);
            }
            else if (node is XmlDeclaration)
            {
                XmlDeclaration dec = node as XmlDeclaration;
                AppendDocumentXmlDeclaration(sb, dec);
                AppendDocumentElementIndication(sb, dec.OwnerDocument);
            }
            else if (node is XmlDocumentType)
            {
                XmlDocumentType docType = node as XmlDocumentType;
                AppendDocumentType(sb, docType);
                AppendDocumentElementIndication(sb, docType.OwnerDocument);
            }
            else if (node is XmlAttribute)
            {
                AppendAttribute(sb, node as XmlAttribute);
            }
            else if (node is XmlElement)
            {
                AppendElement(sb, node as XmlElement);
            }
            else if (node is XmlComment)
            {
                AppendComment(sb, node as XmlComment);
            }
            else if (node is XmlCharacterData)
            {
                AppendText(sb, node as XmlCharacterData);
            }
            else if (node is XmlProcessingInstruction)
            {
                AppendProcessingInstruction(sb, node as XmlProcessingInstruction);
            }
            else if (node == null)
            {
                sb.Append("<NULL>");
            }
            else
            {
                sb.Append("<!--NodeType ").Append(node.NodeType)
                .Append(' ').Append(node.Name)
                .Append('/').Append(node.Value)
                .Append("-->");
            }
            AppendXPath(sb, xpath);
            return(sb.ToString());
        }
Пример #5
0
 public XmlDocumentTypeWrapper(XmlDocumentType documentType)
     : base((XmlNode)documentType)
 {
     this._documentType = documentType;
 }
Пример #6
0
        private void UpdateSmilFile(string smilFullPath, List <string> smilIDs)
        {
            XmlDocument smilXmlDoc = CommonFunctions.CreateXmlDocument(smilFullPath);

            smilXmlDoc.RemoveChild(smilXmlDoc.DocumentType);

            XmlDocumentType type = smilXmlDoc.CreateDocumentType("smil",
                                                                 "-//W3C//DTD SMIL 1.0//EN",
                                                                 "http://www.w3.org/TR/REC-smil/SMIL10.dtd",
                                                                 null);

            smilXmlDoc.InsertBefore(type, smilXmlDoc.DocumentElement);

            XmlNodeList metaList = smilXmlDoc.GetElementsByTagName("meta");

            foreach (XmlNode n in metaList)
            {
                if (n.Attributes.GetNamedItem("name").Value == "dtb:uid")
                {
                    n.Attributes.GetNamedItem("name").Value = "dc:identifier";
                }

                if (n.Attributes.GetNamedItem("name").Value.Contains(":totalElapsedTime"))
                {
                    TimeSpan t = CommonFunctions.GetTimeSpan(n.Attributes.GetNamedItem("content").Value);
                    n.Attributes.GetNamedItem("content").Value = t.ToString();
                }

                string name = n.Attributes.GetNamedItem("name").Value;
                n.Attributes.GetNamedItem("name").Value = name.Replace("dtb:", "ncc:");
            }
            // add format
            XmlNode formatNode = smilXmlDoc.CreateElement(null, "meta", metaList[0].ParentNode.NamespaceURI);

            metaList[0].ParentNode.AppendChild(formatNode);
            formatNode.Attributes.Append(smilXmlDoc.CreateAttribute("name"));
            formatNode.Attributes.Append(smilXmlDoc.CreateAttribute("content"));
            formatNode.Attributes.GetNamedItem("name").Value    = "dc:format";
            formatNode.Attributes.GetNamedItem("content").Value = "Daisy 2.02";

            // add layout
            XmlNode headNode   = smilXmlDoc.GetElementsByTagName("head")[0];
            XmlNode layoutNode = smilXmlDoc.CreateElement(null, "layout", headNode.NamespaceURI);

            headNode.AppendChild(layoutNode);
            XmlNode regionNode = smilXmlDoc.CreateElement(null, "region", headNode.NamespaceURI);

            layoutNode.AppendChild(regionNode);
            regionNode.Attributes.Append(
                smilXmlDoc.CreateAttribute("id"));
            regionNode.Attributes.GetNamedItem("id").Value = "textView";

            // change audio attributes and find total duration
            TimeSpan    duration      = new TimeSpan(0);
            XmlNodeList audioNodeList = smilXmlDoc.GetElementsByTagName("audio");
            int         audioId       = 0;

            foreach (XmlNode n in audioNodeList)
            {
                duration = duration.Add(
                    CalculateTimeDifference(
                        n.Attributes.GetNamedItem("clipBegin").Value,
                        n.Attributes.GetNamedItem("clipEnd").Value));

                XmlAttribute beginAtt = smilXmlDoc.CreateAttribute("clip-begin");
                beginAtt.Value = n.Attributes.GetNamedItem("clipBegin").Value;
                n.Attributes.RemoveNamedItem("clipBegin");

                XmlAttribute endAtt = smilXmlDoc.CreateAttribute("clip-end");
                endAtt.Value = n.Attributes.GetNamedItem("clipEnd").Value;
                n.Attributes.RemoveNamedItem("clipEnd");

                n.Attributes.Append(beginAtt);
                n.Attributes.Append(endAtt);

                n.Attributes.Append(smilXmlDoc.CreateAttribute("id"));
                n.Attributes.GetNamedItem("id").Value = "a" + m_DAISY3Info.Identifier + "audio" + audioId;
                audioId++;
            }

            // add dur to seq.
            XmlNode seqNode = smilXmlDoc.GetElementsByTagName("body")[0].FirstChild;

            if (seqNode.LocalName == "seq")
            {
                seqNode.Attributes.RemoveNamedItem("fill");
                XmlAttribute att = smilXmlDoc.CreateAttribute("dur");
                att.Value = duration.ToString();
                seqNode.Attributes.Append(att);
            }

            // add par node, text node and seq around pars
            XmlNodeList seqChildList = seqNode.ChildNodes;

            MessageBox.Show("SmilID :" + smilIDs.Count.ToString());
            for (int i = 0; i < seqChildList.Count; i++)
            {
                XmlNode parNode = seqChildList[i];
                if (parNode.Attributes.GetNamedItem("id") != null &&
                    smilIDs.Contains(parNode.Attributes.GetNamedItem("id").Value))
                {
                    string  strID      = parNode.Attributes.GetNamedItem("id").Value;
                    XmlNode seqParNode = smilXmlDoc.CreateElement(null, "par", seqNode.NamespaceURI);
                    seqNode.AppendChild(seqParNode);

                    XmlNode textNode = smilXmlDoc.CreateElement(null, "text", seqNode.NamespaceURI);
                    seqParNode.AppendChild(textNode);
                    textNode.Attributes.Append(smilXmlDoc.CreateAttribute("src"));
                    textNode.Attributes.GetNamedItem("src").Value = "ncc.html#" + m_SmilNccIDMap[strID];

                    textNode.Attributes.Append(smilXmlDoc.CreateAttribute("id"));
                    textNode.Attributes.GetNamedItem("id").Value = strID;
                    XmlNode seqNode_FirstParChild = smilXmlDoc.CreateElement(null, "seq", seqNode.NamespaceURI);
                    seqParNode.AppendChild(seqNode_FirstParChild);

                    // copy all pars from primary seq to child seq

                    for (int j = i; j < seqChildList.Count; j++)
                    {
                        //MessageBox.Show ( j.ToString () );
                        XmlNode n = seqNode.ChildNodes[j];
                        if (n != null && n.LocalName == "par" &&
                            n.Attributes.GetNamedItem("id") != null &&
                            (n.Attributes.GetNamedItem("id").Value == strID ||
                             !smilIDs.Contains(n.Attributes.GetNamedItem("id").Value)))
                        {
                            XmlNode par_internal = n.CloneNode(true);


                            if (par_internal.LocalName == "par" &&
                                par_internal.FirstChild.LocalName == "audio")
                            {
                                seqNode_FirstParChild.AppendChild(par_internal.FirstChild);
                                //MessageBox.Show ( n.LocalName );
                            }
                            else
                            {
                                MessageBox.Show(n.FirstChild.Attributes.GetNamedItem("clip-begin").Value);
                                break;
                            }
                        }
                    }
                }
            }    //foreach id ends

            for (int i = seqNode.ChildNodes.Count - 1; i >= 0; i--)
            {
                if (seqNode.ChildNodes[i].LocalName == "par" &&
                    seqNode.ChildNodes[i].FirstChild.LocalName == "audio")
                {
                    seqNode.RemoveChild(seqNode.ChildNodes[i]);

                    System.Media.SystemSounds.Asterisk.Play();
                }
                else
                {
                    MessageBox.Show(seqNode.ChildNodes[i].LocalName + " : " + seqNode.ChildNodes[i].FirstChild.LocalName + " : not removed");
                }
            }

            //seqNode.RemoveAll ();
            //seqNode.AppendChild ( ParqNodeClone );
            // add endsync attribute to par
            XmlNodeList parList = smilXmlDoc.GetElementsByTagName("par");

            foreach (XmlNode n in parList)
            {
                if (n.Attributes.GetNamedItem("endsync") == null)
                {
                    n.Attributes.Append(smilXmlDoc.CreateAttribute("endsync"));
                    n.Attributes.GetNamedItem("endsync").Value = "last";
                }
            }

            CommonFunctions.WriteXmlDocumentToFile(smilXmlDoc, smilFullPath);
            smilXmlDoc = null;
            RemoveSmilSmlns(smilFullPath);
        }
 public void GetReady()
 {
     document = new XmlDocument();
     docType  = document.CreateDocumentType("book", null, null, "<!ELEMENT book ANY>");
     document.AppendChild(docType);
 }
Пример #8
0
    // 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);
    }
Пример #9
0
        static void ExportX3D()
        {
            ClearConsole();

            try
            {
                // grab the selected objects
                Transform[] trs = Selection.GetTransforms(SelectionMode.TopLevel);

                // get a path to save the file
                string file = EditorUtility.SaveFilePanel("Save X3D file as", "${HOME}/Desktop", "", "x3d");
                outputPath = Path.GetDirectoryName(file);

                if (file.Length == 0)
                {
                    // TODO output error
                    return;
                }

                xml = new XmlDocument();

                defNamesInUse = new List <string>();

                XmlNode xmlHeader = xml.CreateXmlDeclaration("1.0", "UTF-8", null);
                xml.AppendChild(xmlHeader);

                XmlDocumentType docType = xml.CreateDocumentType("X3D", "http://www.web3d.org/specifications/x3d-3.3.dtd", null, null);
                xml.AppendChild(docType);

                X3DNode = CreateNode("X3D");
                xml.AppendChild(X3DNode);
                XmlNamespaceManager nms = new XmlNamespaceManager(xml.NameTable);
                nms.AddNamespace("slm", "http://www.v-slam.org");
                sceneNode = CreateNode("Scene");
                X3DNode.AppendChild(sceneNode);

                ExportRenderSettings();

                XmlNode lhToRh = CreateNode("Transform");
                AddXmlAttribute(lhToRh, "scale", "1 1 -1");
                sceneNode.AppendChild(lhToRh);

                sceneNode = lhToRh;

                currentNodeIndex = 0;
                numNodesToExport = 0;

                // Count number of nodes for progress bar
                foreach (Transform tr in trs)
                {
                    numNodesToExport += CountNodes(tr);
                }

                foreach (Transform tr in trs)
                {
                    sceneNode.AppendChild(TransformToX3D(tr));
                }

                xml.Save(file);
            }
            catch (System.Exception e)
            {
                Debug.LogError(e.ToString());
            }

            EditorUtility.ClearProgressBar();
        }
Пример #10
0
        /**
         * Writes the daventure data into the given file.
         *
         * @param folderName
         *            Folder where to write the data
         * @param adventureData
         *            Adventure data to write in the file
         * @param valid
         *            True if the adventure is valid (can be executed in the
         *            engine), false otherwise
         * @return True if the operation was succesfully completed, false otherwise
         */

        public static bool writeData(string folderName, AdventureDataControl adventureData, bool valid)
        {
            bool dataSaved = false;

            // Create the necessary elements for building the DOM
            doc = new XmlDocument();

            // Delete the previous XML files in the root of the project dir
            //DirectoryInfo projectFolder = new DirectoryInfo(folderName);
            //if (projectFolder.Exists)
            //{
            //    foreach (FileInfo file in projectFolder.GetFiles())
            //    {
            //        file.Delete();
            //    }
            //    foreach (DirectoryInfo dir in projectFolder.GetDirectories())
            //    {
            //        dir.Delete(true);
            //    }
            //}

            // Add the special asset files
            // TODO AssetsController.addSpecialAssets();

            /** ******* START WRITING THE DESCRIPTOR ********* */
            // Pick the main node for the descriptor
            XmlDeclaration  declaration    = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
            XmlDocumentType typeDescriptor = doc.CreateDocumentType("game-descriptor", "SYSTEM", "descriptor.dtd", null);

            doc.AppendChild(declaration);
            doc.AppendChild(typeDescriptor);

            if (!valid)
            {
                DOMWriterUtility.DOMWrite(doc, adventureData, new DescriptorDOMWriter.InvalidAdventureDataControlParam());
            }
            else
            {
                DOMWriterUtility.DOMWrite(doc, adventureData);
            }

            doc.Save(folderName + "/descriptor.xml");
            /** ******** END WRITING THE DESCRIPTOR ********** */

            /** ******* START WRITING THE CHAPTERS ********* */
            // Write every chapter
            XmlDocumentType typeChapter;

            int chapterIndex = 1;

            foreach (Chapter chapter in adventureData.getChapters())
            {
                doc         = new XmlDocument();
                declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
                typeChapter = doc.CreateDocumentType("eAdventure", "SYSTEM", "eadventure.dtd", null);
                doc.AppendChild(declaration);
                doc.AppendChild(typeChapter);

                DOMWriterUtility.DOMWrite(doc, chapter);

                doc.Save(folderName + "/chapter" + chapterIndex++ + ".xml");
            }
            /** ******** END WRITING THE CHAPTERS ********** */
            dataSaved = true;
            return(dataSaved);
        }
Пример #11
0
    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/" + filename;

        if (!name.EndsWith(".eaa"))
        {
            name += ".eaa";
        }
        doc.Save(name);
        //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);
    }
        public async Task <object> WriteXmlFile(string fullName, XmlDocument document, XmlDocumentType documentType = null)
        {
            if (string.IsNullOrWhiteSpace(fullName))
            {
                throw new ArgumentNullException(nameof(fullName));
            }

            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            return(await this.writer.Write(fullName : fullName, document : document, documentType : documentType));
        }
Пример #13
0
        /// <summary>
        /// Internal method which generates the RDF/Json Output for a Graph
        /// </summary>
        /// <param name="context">Writer Context</param>
        private void GenerateOutput(RdfXmlWriterContext context)
        {
            context.UseDtd = this._useDTD;

            //Create required variables
            int           nextNamespaceID = 0;
            List <String> tempNamespaces  = new List <String>();

            //Always force RDF Namespace to be correctly defined
            context.Graph.NamespaceMap.AddNamespace("rdf", UriFactory.Create(NamespaceMapper.RDF));

            //Create an XML Document
            XmlDocument    doc  = new XmlDocument();
            XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);

            doc.AppendChild(decl);

            //Create the DOCTYPE declaration and the rdf:RDF element
            StringBuilder entities = new StringBuilder();
            XmlElement    rdf      = doc.CreateElement("rdf:RDF", NamespaceMapper.RDF);

            if (context.Graph.BaseUri != null)
            {
                XmlAttribute baseUri = doc.CreateAttribute("xml:base");
                baseUri.Value = Uri.EscapeUriString(context.Graph.BaseUri.ToString());
                rdf.Attributes.Append(baseUri);
            }

            XmlAttribute ns;
            String       uri;

            entities.Append('\n');
            foreach (String prefix in context.Graph.NamespaceMap.Prefixes)
            {
                uri = context.Graph.NamespaceMap.GetNamespaceUri(prefix).ToString();
                if (!prefix.Equals(String.Empty))
                {
                    entities.AppendLine("\t<!ENTITY " + prefix + " '" + uri + "'>");
                    ns       = doc.CreateAttribute("xmlns:" + prefix);
                    ns.Value = Uri.EscapeUriString(uri.Replace("'", "&apos;"));
                }
                else
                {
                    ns       = doc.CreateAttribute("xmlns");
                    ns.Value = Uri.EscapeUriString(uri);
                }
                rdf.Attributes.Append(ns);
            }
            if (context.UseDtd)
            {
                XmlDocumentType doctype = doc.CreateDocumentType("rdf:RDF", null, null, entities.ToString());
                doc.AppendChild(doctype);
            }
            doc.AppendChild(rdf);

            //Find the Collections
            if (this._compressionLevel >= WriterCompressionLevel.More)
            {
                WriterHelper.FindCollections(context);
            }

            //Find the Type References
            Dictionary <INode, String> typerefs = this.FindTypeReferences(context, ref nextNamespaceID, tempNamespaces, doc);

            //Get the Triples as a Sorted List
            List <Triple> ts = context.Graph.Triples.Where(t => !context.TriplesDone.Contains(t)).ToList();

            ts.Sort();

            //Variables we need to track our writing
            INode lastSubj, lastPred;

            lastSubj = lastPred = null;
            XmlElement subj, pred;

            //Initialise stuff to keep the compiler happy
            subj = doc.CreateElement("rdf:Description", NamespaceMapper.RDF);
            pred = doc.CreateElement("temp");

            for (int i = 0; i < ts.Count; i++)
            {
                Triple t = ts[i];
                if (context.TriplesDone.Contains(t))
                {
                    continue;                                  //Skip if already done
                }
                if (lastSubj == null || !t.Subject.Equals(lastSubj))
                {
                    //Start a new set of Triples
                    //Validate Subject
                    //Use a Type Reference if applicable
                    if (typerefs.ContainsKey(t.Subject))
                    {
                        String tref = typerefs[t.Subject];
                        String tprefix;
                        if (tref.StartsWith(":"))
                        {
                            tprefix = String.Empty;
                        }
                        else if (tref.Contains(":"))
                        {
                            tprefix = tref.Substring(0, tref.IndexOf(':'));
                        }
                        else
                        {
                            tprefix = String.Empty;
                        }
                        subj = doc.CreateElement(tref, context.Graph.NamespaceMap.GetNamespaceUri(tprefix).ToString());
                    }
                    else
                    {
                        subj = doc.CreateElement("rdf:Description", NamespaceMapper.RDF);
                    }

                    //Write out the Subject
                    doc.DocumentElement.AppendChild(subj);
                    lastSubj = t.Subject;

                    //Apply appropriate attributes
                    switch (t.Subject.NodeType)
                    {
                    case NodeType.GraphLiteral:
                        throw new RdfOutputException(WriterErrorMessages.GraphLiteralsUnserializable("RDF/XML"));

                    case NodeType.Literal:
                        throw new RdfOutputException(WriterErrorMessages.LiteralSubjectsUnserializable("RDF/XML"));

                    case NodeType.Blank:
                        if (context.Collections.ContainsKey(t.Subject))
                        {
                            this.GenerateCollectionOutput(context, t.Subject, subj, ref nextNamespaceID, tempNamespaces, doc);
                        }
                        else
                        {
                            XmlAttribute nodeID = doc.CreateAttribute("rdf:nodeID", NamespaceMapper.RDF);
                            nodeID.Value = context.BlankNodeMapper.GetOutputID(((IBlankNode)t.Subject).InternalID);
                            subj.Attributes.Append(nodeID);
                        }
                        break;

                    case NodeType.Uri:
                        this.GenerateUriOutput(context, (IUriNode)t.Subject, "rdf:about", tempNamespaces, subj, doc);
                        break;

                    default:
                        throw new RdfOutputException(WriterErrorMessages.UnknownNodeTypeUnserializable("RDF/XML"));
                    }

                    //Write the Predicate
                    pred = this.GeneratePredicateNode(context, t.Predicate, ref nextNamespaceID, tempNamespaces, doc, subj);
                    subj.AppendChild(pred);
                    lastPred = t.Predicate;
                }
                else if (lastPred == null || !t.Predicate.Equals(lastPred))
                {
                    //Write the Predicate
                    pred = this.GeneratePredicateNode(context, t.Predicate, ref nextNamespaceID, tempNamespaces, doc, subj);
                    subj.AppendChild(pred);
                    lastPred = t.Predicate;
                }

                //Write the Object
                //Create an Object for the Object
                switch (t.Object.NodeType)
                {
                case NodeType.Blank:
                    if (pred.HasChildNodes || pred.HasAttributes)
                    {
                        //Require a new Predicate
                        pred = this.GeneratePredicateNode(context, t.Predicate, ref nextNamespaceID, tempNamespaces, doc, subj);
                        subj.AppendChild(pred);
                    }

                    if (context.Collections.ContainsKey(t.Object))
                    {
                        //Output a Collection
                        this.GenerateCollectionOutput(context, t.Object, pred, ref nextNamespaceID, tempNamespaces, doc);
                    }
                    else
                    {
                        //Terminate the Blank Node triple by adding a rdf:nodeID attribute
                        XmlAttribute nodeID = doc.CreateAttribute("rdf:nodeID", NamespaceMapper.RDF);
                        nodeID.Value = context.BlankNodeMapper.GetOutputID(((IBlankNode)t.Object).InternalID);
                        pred.Attributes.Append(nodeID);
                    }

                    //Force a new Predicate after Blank Nodes
                    lastPred = null;

                    break;

                case NodeType.GraphLiteral:
                    throw new RdfOutputException(WriterErrorMessages.GraphLiteralsUnserializable("RDF/XML"));

                case NodeType.Literal:
                    ILiteralNode lit = (ILiteralNode)t.Object;

                    if (pred.HasChildNodes || pred.HasAttributes)
                    {
                        //Require a new Predicate
                        pred = this.GeneratePredicateNode(context, t.Predicate, ref nextNamespaceID, tempNamespaces, doc, subj);
                        subj.AppendChild(pred);
                    }

                    this.GenerateLiteralOutput(context, lit, pred, doc);

                    //Force a new Predicate Node after Literals
                    lastPred = null;

                    break;

                case NodeType.Uri:

                    this.GenerateUriOutput(context, (IUriNode)t.Object, "rdf:resource", tempNamespaces, pred, doc);

                    //Force a new Predicate Node after URIs
                    lastPred = null;

                    break;

                default:
                    throw new RdfOutputException(WriterErrorMessages.UnknownNodeTypeUnserializable("RDF/XML"));
                }

                context.TriplesDone.Add(t);
            }

            //Check we haven't failed to output any collections
            foreach (KeyValuePair <INode, OutputRdfCollection> pair in context.Collections)
            {
                if (!pair.Value.HasBeenWritten)
                {
                    if (typerefs.ContainsKey(pair.Key))
                    {
                        String tref = typerefs[pair.Key];
                        String tprefix;
                        if (tref.StartsWith(":"))
                        {
                            tref    = tref.Substring(1);
                            tprefix = String.Empty;
                        }
                        else if (tref.Contains(":"))
                        {
                            tprefix = tref.Substring(0, tref.IndexOf(':'));
                        }
                        else
                        {
                            tprefix = String.Empty;
                        }
                        subj = doc.CreateElement(tref, context.Graph.NamespaceMap.GetNamespaceUri(tprefix).ToString());

                        doc.DocumentElement.AppendChild(subj);

                        this.GenerateCollectionOutput(context, pair.Key, subj, ref nextNamespaceID, tempNamespaces, doc);
                    }
                    else
                    {
                        //Generate an rdf:Description Node with a rdf:nodeID on it
                        XmlElement   colNode = doc.CreateElement("rdf:Description");
                        XmlAttribute nodeID  = doc.CreateAttribute("rdf:nodeID");
                        nodeID.Value = context.BlankNodeMapper.GetOutputID(((IBlankNode)pair.Key).InternalID);
                        colNode.Attributes.Append(nodeID);
                        doc.DocumentElement.AppendChild(colNode);
                        this.GenerateCollectionOutput(context, pair.Key, colNode, ref nextNamespaceID, tempNamespaces, doc);
                        //throw new RdfOutputException("Failed to output a Collection due to an unknown error");
                    }
                }
            }

            //Save to the Output Stream
            InternalXmlWriter writer = new InternalXmlWriter();

            writer.Save(context.Output, doc);

            //Get rid of the Temporary Namespace
            foreach (String tempPrefix in tempNamespaces)
            {
                context.Graph.NamespaceMap.RemoveNamespace(tempPrefix);
            }
        }
Пример #14
0
    // 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);
    }
Пример #15
0
 // Token: 0x06000FAF RID: 4015 RVA: 0x0000D53E File Offset: 0x0000B73E
 public Class178(XmlDocumentType xmlDocumentType_0)
 {
     Class202.ofdixO4zTbIfy();
     base..ctor(xmlDocumentType_0);
     this.object_0 = xmlDocumentType_0;
 }
Пример #16
0
        /**
         * Writes the daventure data into the given file.
         *
         * @param folderName
         *            Folder where to write the data
         * @param adventureData
         *            Adventure data to write in the file
         * @param valid
         *            True if the adventure is valid (can be executed in the
         *            engine), false otherwise
         * @return True if the operation was succesfully completed, false otherwise
         */

        public static bool writeData(string folderName, AdventureDataControl adventureData, bool valid)
        {
            bool dataSaved = false;

            // Create the necessary elements for building the DOM
            doc = new XmlDocument();

            // Delete the previous XML files in the root of the project dir
            //DirectoryInfo projectFolder = new DirectoryInfo(folderName);
            //if (projectFolder.Exists)
            //{
            //    foreach (FileInfo file in projectFolder.GetFiles())
            //    {
            //        file.Delete();
            //    }
            //    foreach (DirectoryInfo dir in projectFolder.GetDirectories())
            //    {
            //        dir.Delete(true);
            //    }
            //}

            // Add the special asset files
            // TODO AssetsController.addSpecialAssets();

            /** ******* START WRITING THE DESCRIPTOR ********* */
            // Pick the main node for the descriptor
            XmlDeclaration  declaration    = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
            XmlDocumentType typeDescriptor = doc.CreateDocumentType("game-descriptor", "SYSTEM", "descriptor.dtd", null);

            doc.AppendChild(declaration);
            doc.AppendChild(typeDescriptor);

            if (!valid)
            {
                DOMWriterUtility.DOMWrite(doc, adventureData, new DescriptorDOMWriter.InvalidAdventureDataControlParam());
            }
            else
            {
                DOMWriterUtility.DOMWrite(doc, adventureData);
            }

            // TODO re-add indentation
            //indentDOM(mainNode, 0);

            // Create the necessary elements for export the DOM into a XML file
            //transformer = tFactory.newTransformer();
            //transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "descriptor.dtd");

            // Create the output buffer, write the DOM and close it
            //fout = new FileOutputStream(folderName + "/descriptor.xml");
            //writeFile = new OutputStreamWriter(fout, "UTF-8");
            //transformer.transform(new DOMSource(doc), new StreamResult(writeFile));
            //writeFile.close();
            //fout.close();
            doc.Save(folderName + "/descriptor.xml");
            /** ******** END WRITING THE DESCRIPTOR ********** */

            /** ******* START WRITING THE CHAPTERS ********* */
            // Write every chapter
            XmlDocumentType typeChapter;

            int chapterIndex = 1;

            foreach (Chapter chapter in adventureData.getChapters())
            {
                doc         = new XmlDocument();
                declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
                typeChapter = doc.CreateDocumentType("eAdventure", "SYSTEM", "eadventure.dtd", null);
                doc.AppendChild(declaration);
                doc.AppendChild(typeChapter);
                // Pick the main node of the chapter

                // TODO FIX THIS and use normal domwriter

                var chapterwriter = new ChapterDOMWriter();

                DOMWriterUtility.DOMWrite(doc, chapter);

                // TODO re-add indentation
                //indentDOM(mainNode, 0);

                //TODO: testing
                //doc = new XmlDocument();

                // Create the necessary elements for export the DOM into a XML file
                //transformer = tFactory.newTransformer();
                //transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "eadventure.dtd");

                // Create the output buffer, write the DOM and close it
                //fout = new FileOutputStream(folderName + "/chapter" + chapterIndex++ + ".xml");
                //writeFile = new OutputStreamWriter(fout, "UTF-8");
                //transformer.transform(new DOMSource(doc), new StreamResult(writeFile));
                //writeFile.close();
                //fout.close();

                doc.Save(folderName + "/chapter" + chapterIndex++ + ".xml");
            }
            /** ******** END WRITING THE CHAPTERS ********** */

            // Update the zip files
            //File.umount( );
            dataSaved = true;
            return(dataSaved);
        }
Пример #17
0
        } // SetOutput(java.io.Writer)

        /** Writes the specified node, recursively. */
        public void Write(XmlNode node)
        {
            // is there anything to do?
            if (node == null)
            {
                return;
            }

            XmlNodeType type = node.NodeType;

            switch (type)
            {
            case XmlNodeType.Document: {
                XmlDocument document = (XmlDocument)node;
                fXML11 = false;     //"1.1".Equals(GetVersion(document));
                if (!fCanonical)
                {
                    if (fXML11)
                    {
                        fOut.WriteLine("<?xml version=\"1.1\" encoding=\"UTF-8\"?>");
                    }
                    else
                    {
                        fOut.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                    }
                    fOut.Flush();
                    Write(document.DocumentType);
                }
                Write(document.DocumentElement);
                break;
            }

            case XmlNodeType.DocumentType: {
                XmlDocumentType doctype = (XmlDocumentType)node;
                fOut.Write("<!DOCTYPE ");
                fOut.Write(doctype.Name);
                String publicId = doctype.PublicId;
                String systemId = doctype.SystemId;
                if (publicId != null)
                {
                    fOut.Write(" PUBLIC '");
                    fOut.Write(publicId);
                    fOut.Write("' '");
                    fOut.Write(systemId);
                    fOut.Write('\'');
                }
                else if (systemId != null)
                {
                    fOut.Write(" SYSTEM '");
                    fOut.Write(systemId);
                    fOut.Write('\'');
                }
                String internalSubset = doctype.InternalSubset;
                if (internalSubset != null)
                {
                    fOut.WriteLine(" [");
                    fOut.Write(internalSubset);
                    fOut.Write(']');
                }
                fOut.WriteLine('>');
                break;
            }

            case XmlNodeType.Element: {
                fOut.Write('<');
                fOut.Write(node.Name);
                XmlAttribute[] attrs = SortAttributes(node.Attributes);
                for (int i = 0; i < attrs.Length; i++)
                {
                    XmlAttribute attr = attrs[i];
                    fOut.Write(' ');
                    fOut.Write(attr.Name);
                    fOut.Write("=\"");
                    NormalizeAndPrint(attr.Value, true);
                    fOut.Write('"');
                }
                fOut.Write('>');
                fOut.Flush();

                XmlNode child = node.FirstChild;
                while (child != null)
                {
                    Write(child);
                    child = child.NextSibling;
                }
                break;
            }

            case XmlNodeType.EntityReference: {
                if (fCanonical)
                {
                    XmlNode child = node.FirstChild;
                    while (child != null)
                    {
                        Write(child);
                        child = child.NextSibling;
                    }
                }
                else
                {
                    fOut.Write('&');
                    fOut.Write(node.Name);
                    fOut.Write(';');
                    fOut.Flush();
                }
                break;
            }

            case XmlNodeType.CDATA: {
                if (fCanonical)
                {
                    NormalizeAndPrint(node.Value, false);
                }
                else
                {
                    fOut.Write("<![CDATA[");
                    fOut.Write(node.Value);
                    fOut.Write("]]>");
                }
                fOut.Flush();
                break;
            }

            case XmlNodeType.SignificantWhitespace:
            case XmlNodeType.Whitespace:
            case XmlNodeType.Text: {
                NormalizeAndPrint(node.Value, false);
                fOut.Flush();
                break;
            }

            case XmlNodeType.ProcessingInstruction: {
                fOut.Write("<?");
                fOut.Write(node.Name);
                String data = node.Value;
                if (data != null && data.Length > 0)
                {
                    fOut.Write(' ');
                    fOut.Write(data);
                }
                fOut.Write("?>");
                fOut.Flush();
                break;
            }

            case XmlNodeType.Comment: {
                if (!fCanonical)
                {
                    fOut.Write("<!--");
                    String comment = node.Value;
                    if (comment != null && comment.Length > 0)
                    {
                        fOut.Write(comment);
                    }
                    fOut.Write("-->");
                    fOut.Flush();
                }
                break;
            }
            }

            if (type == XmlNodeType.Element)
            {
                fOut.Write("</");
                fOut.Write(node.Name);
                fOut.Write('>');
                fOut.Flush();
            }
        } // Write(Node)