public void Builds_xml_document()
        {
            IXmlDocumentBuilder builder  = new XmlDocumentBuilder();
            XmlDocument         document = builder.Build("<test />");

            Assert.That(document.Name, Is.EqualTo("#document"));
            Assert.That(document.ChildNodes.Count, Is.EqualTo(1));
            Assert.That(document.ChildNodes[0].Name, Is.EqualTo("test"));
        }
Example #2
0
        /// <exception cref="javax.xml.parsers.ParserConfigurationException"></exception>
        public static XmlDocument ObtainDocumentFromNode(XmlNode node, bool removeNamespaces)
        {
            XmlDocumentBuilder builder      = documentFactory.NewDocumentBuilder();
            XmlDocument        newDocument  = builder.NewDocument();
            XmlNode            importedNode = newDocument.ImportNode(node, true);

            newDocument.AppendChild(importedNode);
            // clear out any namespace that was brought along by the import (though this may not be desirable in all cases)
            if (removeNamespaces)
            {
                RenameNamespaceRecursive(importedNode, null);
            }
            return(newDocument);
        }
    public void Is_Built_Correctly()
    {
        // Arrange
        const string content =
            @"<?xml version=""1.0"" encoding=""utf-8""?><root id=""-1""></root>";

        var builder = new XmlDocumentBuilder();

        // Act
        var xml = builder
                  .WithContent(content)
                  .Build();

        // Assert
        Assert.AreEqual(content, xml.OuterXml);
    }
Example #4
0
        protected internal XmlDocumentBuilder CreateDocumentBuilder()
        {
            XmlDocumentBuilder builder = null;

            try {
                XmlDocumentBuilderFactory factory = CreateDocumentBuilderFactory();
                builder = factory.NewDocumentBuilder();
                if (this.entityResolver != null)
                {
                    builder.SetEntityResolver(this.entityResolver);
                }
            } catch (XmlParserConfigurationException e) {
                throw new Exception(e.ToString());
            }
            return(builder);
        }
Example #5
0
        public void TestDetection()
        {
            //
            // Open and read the test data file.
            //
            // InputStreamReader isr = null;

            try {
                Stream mask0 = typeof(TestCharsetDetector).Assembly.GetFile("CharsetDetectionTests.xml");
                if (mask0 == null)
                {
                    Errln("Could not open test data file CharsetDetectionTests.xml");
                    return;
                }

                // isr = new InputStreamReader(is, "UTF-8");

                // Set up an xml parser.
                XmlDocumentBuilderFactory factory = ILOG.J2CsMapping.XML.XmlDocumentBuilderFactory
                                                    .NewInstance();

                factory.SetIgnoringComments(true);

                XmlDocumentBuilder builder = factory.NewDocumentBuilder();

                // Parse the xml content from the test case file.
                XmlDocument doc  = builder.Parse(mask0, null);
                XmlElement  root = doc.DocumentElement;

                XmlNodeList testCases = root.GetElementsByTagName("test-case");

                // Process each test case
                for (int n = 0; n < testCases.Count; n += 1)
                {
                    XmlNode testCase                = testCases.Item(n);
                    XmlAttributeCollection attrs    = testCase.Attributes;
                    XmlNodeList            testData = testCase.ChildNodes;
                    StringBuilder          testText = new StringBuilder();
                    String id        = attrs.GetNamedItem("id").Value;
                    String encodings = attrs.GetNamedItem("encodings").Value;

                    // Collect the test case text.
                    for (int t = 0; t < testData.Count; t += 1)
                    {
                        XmlNode textNode = testData.Item(t);

                        testText.Append(textNode.Value);
                    }

                    // Process test text with each encoding / language pair.
                    String testString = testText.ToString();
                    // #if defined(FOUNDATION10) || defined(J2SE13)
                    // ## String[] encodingList = Utility.split(encodings, ' ');
                    // #else
                    String[] encodingList = ILOG.J2CsMapping.Text.RegExUtil.Split(encodings, " ");
                    // #endif

                    for (int e = 0; e < encodingList.Length; e += 1)
                    {
                        CheckEncoding(testString, encodingList[e], id);
                    }
                }
            } catch (Exception e_0) {
                Errln("exception while processing test cases: " + e_0.ToString());
            }
        }
 public void SetUp() => _builder = new XmlDocumentBuilder();