示例#1
0
        public static UPnPComplexType[] Parse(string xml)
        {
            // Parse the XSD Schema
            ArrayList     a = new ArrayList();         // ComplexTypes
            Hashtable     g = new Hashtable();         // Table of Groups
            StringReader  s = new StringReader(xml);
            XmlTextReader X = new XmlTextReader(s);

            while (X.Read())
            {
                switch (X.NodeType)
                {
                case XmlNodeType.Element:
                    switch (X.LocalName)
                    {
                    case "complexType":
                        UPnPComplexType _complextype = ParseComplexType(X);
                        a.Add(_complextype);
                        g[_complextype.Name_NAMESPACE + ":" + _complextype.Name_LOCAL] = _complextype;
                        break;

                    case "group":
                        Group _group = (Group)ParseComplexType(X, new Group());
                        g[_group.Name_NAMESPACE + ":" + _group.Name_LOCAL] = _group;
                        a.Add(_group);
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    break;

                case XmlNodeType.Text:
                    break;
                }
            }
            return((UPnPComplexType[])a.ToArray(typeof(UPnPComplexType)));
        }
示例#2
0
        private static UPnPComplexType ParseComplexType(XmlTextReader X, UPnPComplexType RetVal)
        {
            string elementName = X.LocalName;
            int    count       = 0;
            bool   done        = false;
            DText  P           = new DText();

            P.ATTRMARK = ":";

            RetVal.AddContainer(new GenericContainer());

            do
            {
                switch (X.NodeType)
                {
                case XmlNodeType.Element:
                    switch (X.LocalName)
                    {
                    case "complexType":
                    case "group":
                        ++count;
                        if (X.HasAttributes)
                        {
                            for (int i = 0; i < X.AttributeCount; i++)
                            {
                                X.MoveToAttribute(i);
                                if (X.Name == "name")
                                {
                                    P[0] = X.Value;
                                    if (P.DCOUNT() == 1)
                                    {
                                        RetVal.LocalName = X.Value;
                                        RetVal.NameSpace = X.LookupNamespace("");
                                    }
                                    else
                                    {
                                        RetVal.LocalName = P[2];
                                        RetVal.NameSpace = X.LookupNamespace(P[1]);
                                    }
                                }
                                else if (X.Name == "ref")
                                {
                                    // NOP
                                }
                            }
                            X.MoveToElement();
                        }
                        break;

                    case "sequence":
                    case "choice":
                        RetVal.CurrentContainer.AddCollection(ParseComplexType_SequenceChoice(X));
                        //ParseComplexType_Sequence(X,RetVal);
                        break;

                    case "complexContent":
                        RetVal.AddContainer(new ComplexContent());
                        break;

                    case "simpleContent":
                        RetVal.AddContainer(new SimpleContent());
                        break;

                    case "restriction":
                        Restriction r = new Restriction();
                        if (RetVal.CurrentContainer.GetType() == typeof(ComplexContent))
                        {
                            ((ComplexContent)RetVal.CurrentContainer).RestExt = r;
                        }
                        else if (RetVal.CurrentContainer.GetType() == typeof(SimpleContent))
                        {
                            ((SimpleContent)RetVal.CurrentContainer).RestExt = r;
                        }
                        if (X.HasAttributes)
                        {
                            for (int i = 0; i < X.AttributeCount; i++)
                            {
                                X.MoveToAttribute(i);
                                if (X.Name == "base")
                                {
                                    P[0] = X.Value;
                                    if (P.DCOUNT() == 1)
                                    {
                                        r.baseType   = X.Value;
                                        r.baseTypeNS = X.LookupNamespace("");
                                    }
                                    else
                                    {
                                        r.baseType   = P[2];
                                        r.baseTypeNS = X.LookupNamespace(P[1]);
                                    }
                                }
                            }
                            X.MoveToElement();
                        }
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (X.LocalName == elementName)
                    {
                        --count;
                        if (count == 0)
                        {
                            done = true;
                        }
                    }
                    break;

                case XmlNodeType.Text:
                    break;
                }
            }while(!done && X.Read());
            return(RetVal);
        }