internal static UPnPService Parse(String XML)
        {
            StringReader MyString = new StringReader(XML);
            XmlTextReader XMLDoc = new XmlTextReader(MyString);
            UPnPService RetVal = new UPnPService(1);

            XMLDoc.Read();
            XMLDoc.MoveToContent();

            if (XMLDoc.LocalName == "service")
            {
                if (XMLDoc.AttributeCount > 0)
                {
                    for (int ax = 0; ax < XMLDoc.AttributeCount; ++ax)
                    {
                        XMLDoc.MoveToAttribute(ax);
                        if (XMLDoc.LocalName == "MaxVersion")
                        {
                            RetVal.SetVersion(XMLDoc.Value);
                        }
                    }
                    XMLDoc.MoveToContent();
                    XMLDoc.Read();
                }
                else
                {
                    XMLDoc.Read();
                    XMLDoc.MoveToContent();
                }
                while (XMLDoc.LocalName != "service")
                {
                    switch (XMLDoc.LocalName)
                    {
                        case "serviceType":
                            RetVal.ServiceURN = XMLDoc.ReadString();
                            break;
                        case "serviceId":
                            RetVal.ServiceID = XMLDoc.ReadString();
                            break;
                        case "SCPDURL":
                            RetVal.SCPDURL = XMLDoc.ReadString();
                            break;
                        case "controlURL":
                            RetVal.ControlURL = XMLDoc.ReadString();
                            break;
                        case "eventSubURL":
                            RetVal.EventURL = XMLDoc.ReadString();
                            break;
                        default:
                            break;
                    }
                    XMLDoc.Read();
                    XMLDoc.MoveToContent();
                }
            }
            return (RetVal);
        }
예제 #2
0
파일: UPnPService.cs 프로젝트: Scannow/SWYH
        static internal UPnPService Parse(String XML, int startLine)
        {
            StringReader MyString = new StringReader(XML);
            XmlTextReader XMLDoc = new XmlTextReader(MyString);
            UPnPService RetVal = new UPnPService(1);

            try
            {
                XMLDoc.Read();
                XMLDoc.MoveToContent();

                if (XMLDoc.LocalName == "service")
                {
                    if (XMLDoc.AttributeCount > 0)
                    {
                        for (int ax = 0; ax < XMLDoc.AttributeCount; ++ax)
                        {
                            XMLDoc.MoveToAttribute(ax);
                            if (XMLDoc.LocalName == "MaxVersion")
                            {
                                RetVal.SetVersion(XMLDoc.Value);
                            }
                        }
                        XMLDoc.MoveToContent();
                        XMLDoc.Read();
                    }
                    else
                    {
                        XMLDoc.Read();
                        XMLDoc.MoveToContent();
                    }
                    while (XMLDoc.LocalName != "service")
                    {
                        switch (XMLDoc.LocalName)
                        {
                            case "serviceType":
                                RetVal.ServiceURN = XMLDoc.ReadString();
                                break;
                            case "serviceId":
                                RetVal.ServiceID = XMLDoc.ReadString();
                                break;
                            case "SCPDURL":
                                RetVal.SCPDURL = XMLDoc.ReadString();
                                break;
                            case "controlURL":
                                RetVal.ControlURL = XMLDoc.ReadString();
                                break;
                            case "eventSubURL":
                                RetVal.EventURL = XMLDoc.ReadString();
                                break;
                            default:
                                break;
                        }
                        XMLDoc.Read();
                        XMLDoc.MoveToContent();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new XMLParsingException("Invalid service XML", startLine + XMLDoc.LineNumber, XMLDoc.LinePosition, ex);
            }
            return (RetVal);
        }