Exemplo n.º 1
0
 public MwsXmlBuilder(bool toWrap, ConformanceLevel conformanceLevel)
 {
     builder = new StringBuilder();
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.OmitXmlDeclaration = !toWrap;
     settings.ConformanceLevel = conformanceLevel;
     writer = XmlWriter.Create(builder, settings);
 }
		private static void CheckReaderSettings(XmlReaderSettings settings, ConformanceLevel expectedConformanceLevel)
		{
			Assert.IsFalse(settings.CheckCharacters);
#if NET_4_0 && !__MonoCS__
			Assert.AreEqual(DtdProcessing.Parse, settings.DtdProcessing);
#else
			Assert.IsTrue(settings.ProhibitDtd);
#endif
			Assert.AreEqual(ValidationType.None , settings.ValidationType);
			Assert.IsTrue(settings.CloseInput);
			Assert.IsTrue(settings.IgnoreWhitespace);
			Assert.AreEqual(expectedConformanceLevel, settings.ConformanceLevel);
		}
		private XmlWriterSettings(XmlWriterSettings org)
		{
			checkCharacters = org.checkCharacters;
			closeOutput = org.closeOutput;
			conformance = org.conformance;
			encoding = org.encoding;
			indent = org.indent;
			indentChars = org.indentChars;
			newLineChars = org.newLineChars;
			newLineOnAttributes = org.newLineOnAttributes;
			newLineHandling = org.newLineHandling;
			normalizeNewLines = org.normalizeNewLines;
			outputMethod = org.outputMethod;
			omitXmlDeclaration = org.omitXmlDeclaration;
		}
		public void Reset()
		{
			checkCharacters = true;
			closeOutput = false;
			conformance = ConformanceLevel.Document;
			encoding = Encoding.UTF8;
			indent = false;
			indentChars = "  ";
			newLineChars = Environment.NewLine;
			newLineOnAttributes = false;
			newLineHandling = NewLineHandling.Replace;
			normalizeNewLines = true;
			omitXmlDeclaration = false;
			outputMethod = XmlOutputMethod.AutoDetect;
		}
		public void Reset ()
		{
			checkCharacters = true;
			closeOutput = false; // ? not documented
			conformance = ConformanceLevel.Document;
			encoding = Encoding.UTF8;
			indent = false;
			indentChars = "  ";
			// LAMESPEC: MS.NET says it is "\r\n", but it is silly decision.
			newLineChars = Environment.NewLine;
			newLineOnAttributes = false;
			newLineHandling = NewLineHandling.None;
			omitXmlDeclaration = false;
			outputMethod = XmlOutputMethod.AutoDetect;
		}
Exemplo n.º 6
0
		public void Reset ()
		{
			checkCharacters = true;
			closeOutput = false; // ? not documented
			conformance = ConformanceLevel.Document;
			encoding = Encoding.UTF8;
			indent = false;
			indentChars = "  ";
			newLineChars = "\r\n";
			newLineOnAttributes = false;
			newLineHandling = NewLineHandling.Replace;
			omitXmlDeclaration = false;
			outputMethod = XmlOutputMethod.AutoDetect;
#if NET_4_5
			isAsync = false;
#endif
		}
Exemplo n.º 7
0
		///<summary>
		/// Return an XmlReaderSettings suitable for use in Chorus applications.
		///</summary>
		/// <remarks>
		/// This formats with:
		///		CheckCharacters as 'false',
		///		ProhibitDtd as 'true',
		///		ValidationType as ValidationType.None,
		///		CloseInput as 'true',
		///		IgnoreWhitespace as 'true', and
		///		ConformanceLevel as 'conformanceLevel' parameter.
		/// </remarks>
		/// <param name="conformanceLevel">Document|Fragment</param>
		///<returns>XmlReaderSettings</returns>
		public static XmlReaderSettings CreateXmlReaderSettings(ConformanceLevel conformanceLevel)
		{
			var settings = new XmlReaderSettings
			{
				CheckCharacters = false,
				ConformanceLevel = conformanceLevel,
#if NET_4_0 && !__MonoCS__
				DtdProcessing = DtdProcessing.Parse,
#else
				ProhibitDtd = true,
#endif
				ValidationType = ValidationType.None,
				CloseInput = true,
				IgnoreWhitespace = true
			};
			return settings;
		}
Exemplo n.º 8
0
		///<summary>
		/// Return an XmlWriterSettings suitable for use in Chorus applications.
		///</summary>
		/// <remarks>
		/// This formats with new line on attributes, indents with tab, and encoded in UTF8 with no BOM.
		/// </remarks>
		/// <param name="conformanceLevel">Document|Fragment</param>
		///<returns>XmlWriterSettings</returns>
		public static XmlWriterSettings CreateXmlWriterSettings(ConformanceLevel conformanceLevel)
		{
			var settings = new XmlWriterSettings
							   {
								   NewLineOnAttributes = true,              // New line for each attribute, saves space on a typical Chorus changeset.
								   Indent = true,                           // Indent entities
								   IndentChars = "\t",                      // Tabs for the indent
								   CheckCharacters = false,
								   Encoding = new UTF8Encoding(false),      // UTF8 without a BOM.
								   CloseOutput = true,                      // Close the underlying stream on Close.  This is not the default.
								   ConformanceLevel = conformanceLevel,
								   NewLineChars = "\r\n",                   // Use /r/n for our end of lines
								   NewLineHandling = NewLineHandling.None,  // Assume that the input is as written /r/n
								   OmitXmlDeclaration = false               // The default, an xml declaration is written
							   };
			return settings;
		}
Exemplo n.º 9
0
		public void Reset ()
		{
			checkCharacters = true;
			closeInput = false; // ? not documented
			conformance = ConformanceLevel.Document;
			ignoreComments = false;
			ignoreProcessingInstructions = false;
			ignoreWhitespace = false;
			lineNumberOffset = 0;
			linePositionOffset = 0;
			prohibitDtd = true;
#if MOONLIGHT
			xmlResolver = new XmlXapResolver ();
#else
			schemas = null;
			schemasNeedsInitialization = true;
			validationFlags =
				XsValidationFlags.ProcessIdentityConstraints |
				XsValidationFlags.AllowXmlAttributes;
			validationType = ValidationType.None;
			xmlResolver = new XmlUrlResolver ();
#endif
		}
 public bool Validate(Stream stream, ConformanceLevel conformanceLevel = ConformanceLevel.Auto)
 {
     return(InternalValidate(stream, conformanceLevel));
 }
Exemplo n.º 11
0
        //
        // Private methods
        //
        private void Initialize()
        {
            _nameTable = null;
            _lineNumberOffset = 0;
            _linePositionOffset = 0;
            _checkCharacters = true;
            _conformanceLevel = ConformanceLevel.Document;

            _ignoreWhitespace = false;
            _ignorePIs = false;
            _ignoreComments = false;
            _dtdProcessing = DtdProcessing.Prohibit;
            _closeInput = false;

            _maxCharactersFromEntities = 0;
            _maxCharactersInDocument = 0;


            _useAsync = false;

            _isReadOnly = false;
        }
Exemplo n.º 12
0
 //
 // Public methods
 //
 public void Reset()
 {
     nameTable = null;
     lineNumberOffset = 0;
     linePositionOffset = 0;
     checkCharacters = true;
     conformanceLevel = ConformanceLevel.Document;
     ignoreWhitespace = false;
     ignorePIs = false;
     ignoreComments = false;
     closeInput = false;
     isReadOnly = false;
 }
Exemplo n.º 13
0
 // Called before a root element is written (before the WriteStartElement call)
 //   the conformanceLevel specifies the current conformance level the writer is operating with.
 internal virtual void OnRootElement(ConformanceLevel conformanceLevel) { }
Exemplo n.º 14
0
 public virtual XmlWriter CreateWriter(ConformanceLevel cl)
 {
     return this.XmlWriterTestModule.WriterFactory.CreateWriter(cl);
 }
 internal override void OnRootElement(ConformanceLevel currentConformanceLevel) { 
     // Just remember the current conformance level
     conformanceLevel = currentConformanceLevel;
 }
Exemplo n.º 16
0
        private static XmlWriter AddConformanceWrapper(XmlWriter baseWriter, XmlWriterSettings baseWriterSettings, XmlWriterSettings settings)
        {
            ConformanceLevel confLevel       = ConformanceLevel.Auto;
            bool             checkValues     = false;
            bool             checkNames      = false;
            bool             replaceNewLines = false;
            bool             needWrap        = false;

            if (baseWriterSettings == null)
            {
                // assume the V1 writer already do all conformance checking;
                // wrap only if NewLineHandling == Replace or CheckCharacters is true
                if (settings.NewLineHandling == NewLineHandling.Replace)
                {
                    replaceNewLines = true;
                    needWrap        = true;
                }
                if (settings.CheckCharacters)
                {
                    checkValues = true;
                    needWrap    = true;
                }
            }
            else
            {
                if (settings.ConformanceLevel != baseWriterSettings.ConformanceLevel)
                {
                    confLevel = settings.ConformanceLevel;
                    needWrap  = true;
                }
                if (settings.CheckCharacters && !baseWriterSettings.CheckCharacters)
                {
                    checkValues = true;
                    checkNames  = confLevel == ConformanceLevel.Auto;
                    needWrap    = true;
                }
                if (settings.NewLineHandling == NewLineHandling.Replace &&
                    baseWriterSettings.NewLineHandling == NewLineHandling.None)
                {
                    replaceNewLines = true;
                    needWrap        = true;
                }
            }

            if (needWrap)
            {
                XmlWriter writer = baseWriter;
                if (confLevel != ConformanceLevel.Auto)
                {
                    writer = new XmlWellFormedWriter(writer, settings);
                }
                if (checkValues || replaceNewLines)
                {
                    writer = new XmlCharCheckingWriter(writer, checkValues, checkNames, replaceNewLines, settings.NewLineChars);
                }
                return(writer);
            }
            else
            {
                return(baseWriter);
            }
        }
Exemplo n.º 17
0
 // Called before a root element is written (before the WriteStartElement call)
 //   the conformanceLevel specifies the current conformance level the writer is operating with.
 internal virtual void OnRootElement(ConformanceLevel conformanceLevel)
 {
 }
//
// Public methods
//
        public void Reset() {
            CheckReadOnly( "Reset" );

            nameTable = null;
            xmlResolver = new XmlUrlResolver();
            lineNumberOffset = 0;
            linePositionOffset = 0;
            checkCharacters = true;
            conformanceLevel = ConformanceLevel.Document;

            schemas = null;
            validationType = ValidationType.None;
            validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
            ignoreWhitespace = false;
            ignorePIs = false;
            ignoreComments = false;
            prohibitDtd = true;
            closeInput = false;

            isReadOnly = false;
        }
Exemplo n.º 19
0
 public virtual XmlWriter CreateWriter(ConformanceLevel cl)
 {
     return(this.XmlWriterTestModule.WriterFactory.CreateWriter(cl));
 }
Exemplo n.º 20
0
 public virtual XmlWriter CreateWriter(ConformanceLevel cl)
 {
     return(WriterFactory.CreateWriter(cl));
 }
        //
        // Constructor & finalizer
        //
        internal XmlWellFormedWriter(XmlWriter writer, XmlWriterSettings settings) {
            Debug.Assert(writer != null);
            Debug.Assert(settings != null);
            Debug.Assert(MaxNamespacesWalkCount <= 3);

            this.writer = writer;

            rawWriter = writer as XmlRawWriter;
            predefinedNamespaces = writer as IXmlNamespaceResolver;
            if (rawWriter != null) {
                rawWriter.NamespaceResolver = new NamespaceResolverProxy(this);
            }

            checkCharacters = settings.CheckCharacters;

            conformanceLevel = settings.ConformanceLevel;
            stateTable = (conformanceLevel == ConformanceLevel.Document) ? StateTableDocument : StateTableAuto;

            currentState = State.Start;

            nsStack = new Namespace[NamespaceStackInitialSize];
            nsStack[0].Set("xmlns", XmlReservedNs.NsXmlNs, NamespaceKind.Special);
            nsStack[1].Set("xml", XmlReservedNs.NsXml, NamespaceKind.Special);
            if (predefinedNamespaces == null) {
                nsStack[2].Set(string.Empty, string.Empty, NamespaceKind.Implied);
            }
            else {
                string defaultNs = predefinedNamespaces.LookupNamespace(string.Empty);
                nsStack[2].Set(string.Empty, (defaultNs == null ? string.Empty : defaultNs), NamespaceKind.Implied);
            }
            nsTop = 2;

            elemScopeStack = new ElementScope[ElementStackInitialSize];
            elemScopeStack[0].Set(string.Empty, string.Empty, string.Empty, nsTop);
            elemScopeStack[0].xmlSpace = XmlSpace.None;
            elemScopeStack[0].xmlLang = null;
            elemTop = 0;

            attrStack = new AttrName[AttributeArrayInitialSize];

            attrValue = new StringBuilder();

            hasher = new SecureStringHasher();
        }
        public override void WriteDocType(string name, string pubid, string sysid, string subset) {
            try {
                if (name == null || name.Length == 0) {
                    throw new ArgumentException(Res.GetString(Res.Xml_EmptyName));
                }
                XmlConvert.VerifyQName(name);

                if (conformanceLevel == ConformanceLevel.Fragment) {
                    throw new InvalidOperationException(Res.GetString(Res.Xml_DtdNotAllowedInFragment));
                }

                AdvanceState(Token.Dtd);
                if (dtdWritten) {
                    currentState = State.Error;
                    throw new InvalidOperationException(Res.GetString(Res.Xml_DtdAlreadyWritten));
                }

                if (conformanceLevel == ConformanceLevel.Auto) {
                    conformanceLevel = ConformanceLevel.Document;
                    stateTable = StateTableDocument;
                }

                int i;

                // check characters
                if (checkCharacters) {
                    if (pubid != null) {
                        if ((i = xmlCharType.IsPublicId(pubid)) >= 0) {
                            throw new ArgumentException(Res.GetString(Res.Xml_InvalidCharacter, XmlException.BuildCharExceptionStr(pubid[i])), "pubid");
                        }
                    }
                    if (sysid != null) {
                        if ((i = xmlCharType.IsOnlyCharData(sysid)) >= 0) {
                            throw new ArgumentException(Res.GetString(Res.Xml_InvalidCharacter, XmlException.BuildCharExceptionStr(sysid[i])), "sysid");
                        }
                    }
                    if (subset != null) {
                        if ((i = xmlCharType.IsOnlyCharData(subset)) >= 0) {
                            throw new ArgumentException(Res.GetString(Res.Xml_InvalidCharacter, XmlException.BuildCharExceptionStr(subset[i])), "subset");
                        }
                    }
                }

                // write doctype
                writer.WriteDocType(name, pubid, sysid, subset);
                dtdWritten = true;
            }
            catch {
                currentState = State.Error;
                throw;
            }
        }
        private void WriteStartDocumentImpl(XmlStandalone standalone) {
            try {
                AdvanceState(Token.StartDocument);

                if (conformanceLevel == ConformanceLevel.Auto) {
                    conformanceLevel = ConformanceLevel.Document;
                    stateTable = StateTableDocument;
                }
                else if (conformanceLevel == ConformanceLevel.Fragment) {
                    throw new InvalidOperationException(Res.GetString(Res.Xml_CannotStartDocumentOnFragment));
                }

                if (rawWriter != null) {
                    if (!xmlDeclFollows) {
                        rawWriter.WriteXmlDeclaration(standalone);
                    }
                }
                else {
                    // We do not pass the standalone value here - Dev10 Bug #479769
                    writer.WriteStartDocument();
                }
            }
            catch {
                currentState = State.Error;
                throw;
            }
        }
Exemplo n.º 24
0
        //
        // Private methods
        //
        private void Initialize()
        {
            _encoding = Encoding.UTF8;
            _omitXmlDecl = false;
            _newLineHandling = NewLineHandling.Replace;
            _newLineChars = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix
            _indent = TriState.Unknown;
            _indentChars = "  ";
            _newLineOnAttributes = false;
            _closeOutput = false;
            _namespaceHandling = NamespaceHandling.Default;
            _conformanceLevel = ConformanceLevel.Document;
            _checkCharacters = true;
            _writeEndDocumentOnClose = true;

            _outputMethod = XmlOutputMethod.Xml;
            _cdataSections.Clear();
            _mergeCDataSections = false;
            _mediaType = null;
            _docTypeSystem = null;
            _docTypePublic = null;
            _standalone = XmlStandalone.Omit;
            _doNotEscapeUriAttributes = false;

            _useAsync = false;
            _isReadOnly = false;
        }
        public static string Serialize <T>(object data, bool omitXmlDeclaration = true, ConformanceLevel conformanceLevel = ConformanceLevel.Auto,
                                           Encoding encoding = null, bool formatOutputIndented = true, bool omitXmlNamespace = true)
        {
            if (string.IsNullOrWhiteSpace(data?.ToString()))
            {
                return(null);
            }

            if (encoding == null)
            {
                encoding = Encoding.UTF8;
            }

            // handle the output stream
            XmlWriterSettings settings = new XmlWriterSettings()
            {
                OmitXmlDeclaration = omitXmlDeclaration,
                ConformanceLevel   = conformanceLevel,
                Encoding           = encoding,
                CloseOutput        = true,
                Indent             = formatOutputIndented
            };

            XmlSerializer s   = new XmlSerializer(typeof(T));
            StringBuilder buf = new StringBuilder();
            XmlWriter     w   = XmlWriter.Create(buf, settings);

            if (data is XmlDocument)
            {
                ((XmlDocument)data).Save(w);
            }
            else
            {
                if (omitXmlNamespace)
                {
                    XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                    ns.Add("", "");
                    s.Serialize(w, data, ns);
                }
                else
                {
                    s.Serialize(w, data);
                }
            }
            w.Close();

            return(buf.ToString());
        }
//
// Private methods
//
        void Initialize() {
            encoding = Encoding.UTF8;
            omitXmlDecl = false;
            newLineHandling = NewLineHandling.Replace;
            newLineChars = Environment.NewLine; // "\r\n" on Windows, "\n" on Unix
            indent = TriState.Unknown;
            indentChars = "  ";
            newLineOnAttributes = false;
            closeOutput = false;
            namespaceHandling = NamespaceHandling.Default;
            conformanceLevel = ConformanceLevel.Document;
            checkCharacters = true;
            writeEndDocumentOnClose = true;

#if !SILVERLIGHT
            outputMethod = XmlOutputMethod.Xml;
            cdataSections.Clear();
            mergeCDataSections = false;
            mediaType = null;
            docTypeSystem = null;
            docTypePublic = null;
            standalone = XmlStandalone.Omit;
            doNotEscapeUriAttributes = false;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif
            isReadOnly = false;
        }
Exemplo n.º 27
0
        private List<XmlWriter> GetXmlWriters(Encoding encoding, ConformanceLevel conformanceLevel)
        {
            var xmlWriters = new List<XmlWriter>();
            int count = 0;

            var s = new XmlWriterSettings();
            s.CheckCharacters = true;
            s.Encoding = encoding;

            var ws = new XmlWriterSettings();
            ws.CheckCharacters = false;
            // Set it to true when FileIO is ok
            ws.CloseOutput = false;
            ws.Encoding = encoding;

            s.ConformanceLevel = conformanceLevel;
            ws.ConformanceLevel = conformanceLevel;

            TextWriter tw = new StreamWriter(FilePathUtil.getStream(GenerateTestFileName(count++)));
            xmlWriters.Add(new CoreXml.Test.XLinq.CustomWriter(tw, ws)); // CustomWriter                  
            xmlWriters.Add(XmlWriter.Create(FilePathUtil.getStream(GenerateTestFileName(count++)), s)); // Factory XmlWriter       
            xmlWriters.Add(XmlWriter.Create(FilePathUtil.getStream(GenerateTestFileName(count++)), ws)); // Factory Writer   

            return xmlWriters;
        }
Exemplo n.º 28
0
      public XmlParsingOptions() {

         this.ConformanceLevel = ConformanceLevel.Document;
         this.XmlResolver = new XmlDynamicResolver(Assembly.GetCallingAssembly());
      }
Exemplo n.º 29
0
        /// <summary>
        /// 以UTF8编码方式编写XML。
        /// </summary>
        /// <param name="writeAction">编写操作。</param>
        /// <param name="indent">是否缩进。</param>
        /// <param name="conformanceLevel">指示XML是文档还是片段。</param>
        /// <returns>XML 字符串。</returns>
        public static string WriteUtf8Xml(Action <XmlWriter> writeAction, bool indent = true, ConformanceLevel conformanceLevel = ConformanceLevel.Document)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent           = indent;
            settings.ConformanceLevel = conformanceLevel;
            settings.Encoding         = Encoding.UTF8;
            using (MemoryStream stream = new MemoryStream())
            {
                using (XmlWriter writer = XmlWriter.Create(stream, settings))
                {
                    if (writeAction != null)
                    {
                        writeAction.Invoke(writer);
                    }
                    byte[] content = stream.ToArray();
                    string xml     = Encoding.UTF8.GetString(content, 0, content.Length);
                    return(xml);
                }
            }
        }
Exemplo n.º 30
0
        private XmlWriter AddConformanceWrapper(XmlWriter baseWriter)
        {
            ConformanceLevel  confLevel          = ConformanceLevel.Auto;
            XmlWriterSettings?baseWriterSettings = baseWriter.Settings;
            bool checkValues     = false;
            bool checkNames      = false;
            bool replaceNewLines = false;
            bool needWrap        = false;

            if (baseWriterSettings == null)
            {
                // assume the V1 writer already do all conformance checking;
                // wrap only if NewLineHandling == Replace or CheckCharacters is true
                if (_newLineHandling == NewLineHandling.Replace)
                {
                    replaceNewLines = true;
                    needWrap        = true;
                }
                if (_checkCharacters)
                {
                    checkValues = true;
                    needWrap    = true;
                }
            }
            else
            {
                if (_conformanceLevel != baseWriterSettings.ConformanceLevel)
                {
                    confLevel = this.ConformanceLevel;
                    needWrap  = true;
                }
                if (_checkCharacters && !baseWriterSettings.CheckCharacters)
                {
                    checkValues = true;
                    checkNames  = confLevel == ConformanceLevel.Auto;
                    needWrap    = true;
                }
                if (_newLineHandling == NewLineHandling.Replace &&
                    baseWriterSettings.NewLineHandling == NewLineHandling.None)
                {
                    replaceNewLines = true;
                    needWrap        = true;
                }
            }

            XmlWriter writer = baseWriter;

            if (needWrap)
            {
                if (confLevel != ConformanceLevel.Auto)
                {
                    writer = new XmlWellFormedWriter(writer, this);
                }
                if (checkValues || replaceNewLines)
                {
                    writer = new XmlCharCheckingWriter(writer, checkValues, checkNames, replaceNewLines, this.NewLineChars);
                }
            }

            if (this.IsQuerySpecific && (baseWriterSettings == null || !baseWriterSettings.IsQuerySpecific))
            {
                // Create QueryOutputWriterV1 if CData sections or DocType need to be tracked
                writer = new QueryOutputWriterV1(writer, this);
            }

            return(writer);
        }
Exemplo n.º 31
0
        private void WriteStartDocumentImpl(XmlStandalone standalone)
        {
            try
            {
                AdvanceState(Token.StartDocument);

                if (_conformanceLevel == ConformanceLevel.Auto)
                {
                    _conformanceLevel = ConformanceLevel.Document;
                    _stateTable = s_stateTableDocument;
                }
                else if (_conformanceLevel == ConformanceLevel.Fragment)
                {
                    throw new InvalidOperationException(SR.Xml_CannotStartDocumentOnFragment);
                }

                if (_rawWriter != null)
                {
                    if (!_xmlDeclFollows)
                    {
                        _rawWriter.WriteXmlDeclaration(standalone);
                    }
                }
                else
                {
                    // We do not pass the standalone value here
                    _writer.WriteStartDocument();
                }
            }
            catch
            {
                _currentState = State.Error;
                throw;
            }
        }
Exemplo n.º 32
0
        //
        // Constructor & finalizer
        //
        internal XmlWellFormedWriter(XmlWriter writer, XmlWriterSettings settings)
        {
            Debug.Assert(writer != null);
            Debug.Assert(settings != null);
            Debug.Assert(MaxNamespacesWalkCount <= 3);

            _writer = writer;

            _rawWriter = writer as XmlRawWriter;
            _predefinedNamespaces = writer as IXmlNamespaceResolver;
            if (_rawWriter != null)
            {
                _rawWriter.NamespaceResolver = new NamespaceResolverProxy(this);
            }

            _checkCharacters = settings.CheckCharacters;
            _omitDuplNamespaces = (settings.NamespaceHandling & NamespaceHandling.OmitDuplicates) != 0;
            _writeEndDocumentOnClose = settings.WriteEndDocumentOnClose;

            _conformanceLevel = settings.ConformanceLevel;
            _stateTable = (_conformanceLevel == ConformanceLevel.Document) ? s_stateTableDocument : s_stateTableAuto;

            _currentState = State.Start;

            _nsStack = new Namespace[NamespaceStackInitialSize];
            _nsStack[0].Set("xmlns", XmlReservedNs.NsXmlNs, NamespaceKind.Special);
            _nsStack[1].Set("xml", XmlReservedNs.NsXml, NamespaceKind.Special);
            if (_predefinedNamespaces == null)
            {
                _nsStack[2].Set(string.Empty, string.Empty, NamespaceKind.Implied);
            }
            else
            {
                string defaultNs = _predefinedNamespaces.LookupNamespace(string.Empty);
                _nsStack[2].Set(string.Empty, (defaultNs == null ? string.Empty : defaultNs), NamespaceKind.Implied);
            }
            _nsTop = 2;

            _elemScopeStack = new ElementScope[ElementStackInitialSize];
            _elemScopeStack[0].Set(string.Empty, string.Empty, string.Empty, _nsTop);
            _elemScopeStack[0].xmlSpace = XmlSpace.None;
            _elemScopeStack[0].xmlLang = null;
            _elemTop = 0;

            _attrStack = new AttrName[AttributeArrayInitialSize];

            _hasher = new SecureStringHasher();
        }
Exemplo n.º 33
0
        private void Initialize(XmlResolver resolver)
        {
            _nameTable = null;
            if (!EnableLegacyXmlSettings())
            {
                _xmlResolver = resolver;
                // limit the entity resolving to 10 million character. the caller can still
                // override it to any other value or set it to zero for unlimiting it
                _maxCharactersFromEntities = (long)1e7;
            }
            else
            {
                _xmlResolver = (resolver == null ? CreateDefaultResolver() : resolver);
                _maxCharactersFromEntities = 0;
            }
            _lineNumberOffset = 0;
            _linePositionOffset = 0;
            _checkCharacters = true;
            _conformanceLevel = ConformanceLevel.Document;

            _ignoreWhitespace = false;
            _ignorePIs = false;
            _ignoreComments = false;
            _dtdProcessing = DtdProcessing.Prohibit;
            _closeInput = false;

            _maxCharactersInDocument = 0;

            _schemas = null;
            _validationType = ValidationType.None;
            _validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            _validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;

            _useAsync = false;

            _isReadOnly = false;
            IsXmlResolverSet = false;
        }
Exemplo n.º 34
0
        void Initialize(XmlResolver resolver) {
            nameTable = null;
#if !SILVERLIGHT
            if (!EnableLegacyXmlSettings())
            {
                xmlResolver = resolver;
                // limit the entity resolving to 10 million character. the caller can still
                // override it to any other value or set it to zero for unlimiting it
                maxCharactersFromEntities = (long) 1e7;
            }
            else
#endif            
            {
                xmlResolver = (resolver == null ? CreateDefaultResolver() : resolver);
                maxCharactersFromEntities = 0;
            }
            lineNumberOffset = 0;
            linePositionOffset = 0;
            checkCharacters = true;
            conformanceLevel = ConformanceLevel.Document;

            ignoreWhitespace = false;
            ignorePIs = false;
            ignoreComments = false;
            dtdProcessing = DtdProcessing.Prohibit;
            closeInput = false;

            maxCharactersInDocument = 0;

#if !SILVERLIGHT
            schemas = null;
            validationType = ValidationType.None;
            validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif

            isReadOnly = false;
#if !SILVERLIGHT
            IsXmlResolverSet = false;
#endif
        }
Exemplo n.º 35
0
 public static XmlReaderSettings CreateSettings(ConformanceLevel level, DtdProcessing dtdProcessing, XmlUrlResolver resolver,
                                                XmlSchemaValidationFlags validationFlags, ValidationType validationType, XmlSchemaSet schemaSet, ValidationEventHandler onErrorHandler)
 {
     return(CreateSettings(false, false, true, false, level, dtdProcessing, resolver, validationFlags, validationType, schemaSet, onErrorHandler));
 }
Exemplo n.º 36
0
 static XmlReaderSettings CreateReaderSettings(XamlXmlReaderSettings settings, ConformanceLevel conformance = ConformanceLevel.Document, bool?closeInput = null)
 {
     return(new XmlReaderSettings
     {
         CloseInput = closeInput ?? settings?.CloseInput ?? false,
         IgnoreComments = true,
         IgnoreProcessingInstructions = true,
         ConformanceLevel = conformance
     });
 }
Exemplo n.º 37
0
 public XPathSerializationOptions()
 {
     this.ConformanceLevel = ConformanceLevel.Auto;
 }
Exemplo n.º 38
0
 private void StartFragment()
 {
     _conformanceLevel = ConformanceLevel.Fragment;
     Debug.Assert(_stateTable == s_stateTableAuto);
 }
        void Initialize(XmlResolver resolver) {
            nameTable = null;
            xmlResolver = (resolver == null ? CreateDefaultResolver() : resolver);
            lineNumberOffset = 0;
            linePositionOffset = 0;
            checkCharacters = true;
            conformanceLevel = ConformanceLevel.Document;

            ignoreWhitespace = false;
            ignorePIs = false;
            ignoreComments = false;
            dtdProcessing = DtdProcessing.Prohibit;
            closeInput = false;

            maxCharactersFromEntities = 0;
            maxCharactersInDocument = 0;

#if !SILVERLIGHT
            schemas = null;
            validationType = ValidationType.None;
            validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif

            isReadOnly = false;
#if !SILVERLIGHT
            IsXmlResolverSet = false;
#endif
        }
Exemplo n.º 40
0
        public override void WriteDocType(string name, string pubid, string sysid, string subset)
        {
            try
            {
                if (name == null || name.Length == 0)
                {
                    throw new ArgumentException(SR.Xml_EmptyName);
                }
                XmlConvert.VerifyQName(name, ExceptionType.XmlException);

                if (_conformanceLevel == ConformanceLevel.Fragment)
                {
                    throw new InvalidOperationException(SR.Xml_DtdNotAllowedInFragment);
                }

                AdvanceState(Token.Dtd);
                if (_dtdWritten)
                {
                    _currentState = State.Error;
                    throw new InvalidOperationException(SR.Xml_DtdAlreadyWritten);
                }

                if (_conformanceLevel == ConformanceLevel.Auto)
                {
                    _conformanceLevel = ConformanceLevel.Document;
                    _stateTable = s_stateTableDocument;
                }

                int i;

                // check characters
                if (_checkCharacters)
                {
                    if (pubid != null)
                    {
                        if ((i = _xmlCharType.IsPublicId(pubid)) >= 0)
                        {
                            throw new ArgumentException(SR.Format(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(pubid, i)), nameof(pubid));
                        }
                    }
                    if (sysid != null)
                    {
                        if ((i = _xmlCharType.IsOnlyCharData(sysid)) >= 0)
                        {
                            throw new ArgumentException(SR.Format(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(sysid, i)), nameof(sysid));
                        }
                    }
                    if (subset != null)
                    {
                        if ((i = _xmlCharType.IsOnlyCharData(subset)) >= 0)
                        {
                            throw new ArgumentException(SR.Format(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(subset, i)), nameof(subset));
                        }
                    }
                }

                // write doctype
                _writer.WriteDocType(name, pubid, sysid, subset);
                _dtdWritten = true;
            }
            catch
            {
                _currentState = State.Error;
                throw;
            }
        }
 internal override void OnRootElement(ConformanceLevel currentConformanceLevel)
 {
     this.conformanceLevel = currentConformanceLevel;
 }
Exemplo n.º 42
0
 public XmlSerializationOptions() {
    this.ConformanceLevel = ConformanceLevel.Auto;
 }
Exemplo n.º 43
0
 public static XmlReaderSettings CreateSettings(ConformanceLevel level, DtdProcessing dtdProcessing, XmlUrlResolver resolver,
                                                XmlSchemaValidationFlags validationFlags, ValidationType validationType)
 {
     return(CreateSettings(false, false, true, false, level, dtdProcessing, resolver, validationFlags, validationType, null, null));
 }