Esempio n. 1
0
        /// <summary>
        /// Creates a new <see cref="ASQName"/> object from a local name. The default namespace will
        /// be used.
        /// </summary>
        /// <param name="localName">The local name of the XML name. This is the name of the XML
        /// element or attribute without the namespace. If this is the string "*", the QName will
        /// match XML elements and attributes with any name in any namespace. Otherwise, its namespace
        /// will be set to the default XML namespace.</param>
        public ASQName(string?localName)
        {
            if (localName != null && localName.Length == 1 && localName[0] == '*')
            {
                (uri, prefix) = (null, null);
            }
            else
            {
                ASNamespace defaultNS = ASNamespace.getDefault();
                (uri, prefix) = (defaultNS.uri, defaultNS.prefix);
            }

            this.localName = ASString.AS_convertString(localName);
        }
Esempio n. 2
0
        /// <summary>
        /// Checks if the given <see cref="ASQName"/> is a valid node name for an element, attribute
        /// or processing instruction. If it is not valid, attempts to create a valid name by removing
        /// the namespace prefix from the name, or by substituting a default namespace URI if the
        /// name has a null namespace URI.
        /// </summary>
        ///
        /// <param name="name">The <see cref="ASQName"/> instance to check.</param>
        /// <param name="nodeType">Must be one of <see cref="XMLNodeType.ELEMENT"/>, <see cref="XMLNodeType.ATTRIBUTE"/>
        /// or <see cref="XMLNodeType.PROCESSING_INSTRUCTION"/>.</param>
        /// <param name="defaultNS">The default namespace to use if the namespace URI of <paramref name="name"/>
        /// is null. If this is null, the value of <see cref="ASNamespace.getDefault()"/> is used if
        /// <paramref name="nodeType"/> if <see cref="XMLNodeType.ELEMENT"/>, and <see cref="ASNamespace.@public"/>
        /// otherwise.</param>
        ///
        /// <returns>If <paramref name="name"/> is a valid name for a node of the given type, returns
        /// <paramref name="name"/>; if a new valid name could be created by removing the namespace prefix
        /// and/or by substituting a default namespace URI, returns the new name; otherwise, returns null.</returns>
        public static ASQName?tryMakeValidNodeName(ASQName?name, XMLNodeType nodeType, ASNamespace?defaultNS = null)
        {
            if (name == null || !isValidName(name.localName))
            {
                return(null);
            }

            switch (nodeType)
            {
            case XMLNodeType.ELEMENT:
                if (name.uri == null)
                {
                    return(new ASQName(defaultNS ?? ASNamespace.getDefault(), name.localName));
                }
                break;

            case XMLNodeType.PROCESSING_INSTRUCTION:
                if (name.uri == null || name.uri.Length != 0)
                {
                    return(new ASQName(ASNamespace.@public, name.localName));
                }
                break;

            case XMLNodeType.ATTRIBUTE: {
                if (name.uri == null)
                {
                    name = new ASQName(defaultNS ?? ASNamespace.@public, name.localName);
                }
                else if (name.prefix != null &&
                         ((name.prefix.Length == 0 && name.uri.Length != 0) || name.prefix == "xmlns"))
                {
                    name = ASQName.unsafeCreate(prefix: null, name.uri, name.localName);
                }

                if (name.uri !.Length == 0 && name.localName == "xmlns")
                {
                    return(null);
                }

                break;
            }
            }

            return(name);
        }
Esempio n. 3
0
        private void _init(string str)
        {
            m_str         = str;
            m_pos         = 0;
            m_curLine     = 1;
            m_defaultNS   = ASNamespace.getDefault();
            m_parserFlags = 0;

            var xmlSettings = ASXML.internalSettings;

            if (xmlSettings.ignoreComments)
            {
                m_parserFlags |= FLAG_IGNORE_COMMENTS;
            }
            if (xmlSettings.ignoreProcessingInstructions)
            {
                m_parserFlags |= FLAG_IGNORE_PI;
            }
            if (xmlSettings.ignoreWhitespace)
            {
                m_parserFlags |= FLAG_IGNORE_SPACE;
            }

            m_nsInScope.clear();
            m_nsInScopePtrs.clear();
            m_parserStack.clear();
            m_nodeStack.clear();
            m_unresolvedAttrs.clear();

            if (m_buffer == null)
            {
                m_buffer = new char[128];
            }

            if (m_namePool == null)
            {
                m_namePool = new NamePool();
            }
        }