예제 #1
0
        internal static Namespace Parse(XMLLib lib, Context cx, Object uriValue)
        {
            String prefix;
            String uri;

            if (uriValue is Namespace)
            {
                Namespace ns = (Namespace)uriValue;
                prefix = ns.Prefix;
                uri    = ns.Uri;
            }
            else if (uriValue is QName)
            {
                QName qname = (QName)uriValue;
                uri = qname.Uri;
                if (uri != null)
                {
                    prefix = qname.Prefix;
                }
                else
                {
                    uri    = qname.ToString();
                    prefix = null;
                }
            }
            else
            {
                uri    = ScriptConvert.ToString(uriValue);
                prefix = (uri.Length == 0) ? "" : null;
            }

            return(new Namespace(lib, prefix, uri));
        }
예제 #2
0
        public static Namespace Parse(XMLLib lib, Context cx, Object prefixValue,
                                      Object uriValue)
        {
            String prefix;
            String uri;

            if (uriValue is QName)
            {
                QName qname = (QName)uriValue;
                uri = qname.Uri;
                if (uri == null)
                {
                    uri = qname.ToString();
                }
            }
            else
            {
                uri = ScriptConvert.ToString(uriValue);
            }

            if (uri.Length == 0)
            {
                if (prefixValue == Undefined.Value)
                {
                    prefix = "";
                }
                else
                {
                    prefix = ScriptConvert.ToString(prefixValue);
                    if (prefix.Length != 0)
                    {
                        throw ScriptRuntime.TypeError(
                                  "Illegal prefix '" + prefix + "' for 'no namespace'.");
                    }
                }
            }
            else if (prefixValue == Undefined.Value)
            {
                prefix = "";
            }
            else if (!lib.IsXMLName(cx, prefixValue))
            {
                prefix = "";
            }
            else
            {
                prefix = ScriptConvert.ToString(prefixValue);
            }

            return(new Namespace(lib, prefix, uri));
        }