Ejemplo n.º 1
0
        public XMLList(XMLLib lib, object inputObject)
            : this(lib)
        {
            string frag;
            if (inputObject == null || inputObject is Undefined)
            {
                frag = "";
            }
            else if (inputObject is XML)
            {
                XML xml = (XML)inputObject;
                Add(xml);
            }
            else if (inputObject is XMLList)
            {
                XMLList xmll = (XMLList)inputObject;
                AddRange(xmll);
            }
            else
            {
                frag = ScriptConvert.ToString(inputObject).Trim();
                if (!frag.StartsWith("<>"))
                {
                    frag = "<>" + frag + "</>";
                }
                frag = "<fragment>" + frag.Substring(2);
                if (!frag.EndsWith("</>"))
                {
                    throw ScriptRuntime.TypeError("XML with anonymous tag missing end anonymous tag");
                }
                frag = frag.Substring(0, frag.Length - 3) + "</fragment>";

                XML orgXML = XML.CreateFromJS(lib, frag);

                // Now orphan the children and add them to our XMLList.
                XMLList children = (XMLList)orgXML.Children();
                AddRange(children);
            }
        }