Example #1
0
        internal XmlDocumentBuilderFactory CreateDocumentBuilderFactory()
        {
            XmlDocumentBuilderFactory factory = XmlDocumentBuilderFactory.NewInstance();

            factory.SetNamespaceAware(true);
            return(factory);
        }
Example #2
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 #3
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());
            }
        }