当前位置: 首页>>代码示例>>C#>>正文


C# XmlTextReader.LookupNamespace方法代码示例

本文整理汇总了C#中System.Xml.XmlTextReader.LookupNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.LookupNamespace方法的具体用法?C# XmlTextReader.LookupNamespace怎么用?C# XmlTextReader.LookupNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlTextReader的用法示例。


在下文中一共展示了XmlTextReader.LookupNamespace方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EmptyElementInNamespace

		public void EmptyElementInNamespace ()
		{
			string xml = @"<foo:bar xmlns:foo='http://foo/' />";
			XmlReader xmlReader =
				new XmlTextReader (new StringReader (xml));

			AssertStartDocument (xmlReader);

			AssertNode (
				xmlReader, // xmlReader
				XmlNodeType.Element, // nodeType
				0, // depth
				true, // isEmptyElement
				"foo:bar", // name
				"foo", // prefix
				"bar", // localName
				"http://foo/", // namespaceURI
				String.Empty, // value
				1 // attributeCount
			);

			AssertAttribute (
				xmlReader, // xmlReader
				"xmlns:foo", // name
				"xmlns", // prefix
				"foo", // localName
				"http://www.w3.org/2000/xmlns/", // namespaceURI
				"http://foo/" // value
			);

			AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));

			AssertEndDocument (xmlReader);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:34,代码来源:XmlTextReaderTests.cs

示例2: ParseStateVarXml

        private void ParseStateVarXml(String evented, String multicasted, XmlTextReader XMLDoc)
        {
            //			if (XML=="")
            //			{
            //				return;
            //			}

            string ComplexType = "";
            string ComplexTypeNS = "";
            UPnPComplexType CT = null;
            DText P = new DText();
            P.ATTRMARK = ":";

            string minval = null;
            string maxval = null;
            string stepval = null;
            bool HasDef = false;

            string name = "";
            string DataType = "";
            string DefaultValue = null;
            ArrayList allowedValueList = new ArrayList();
            string LocalName = "";
            string lname2 = "";

            //			StringReader MyString = new StringReader(XML);
            //			XmlTextReader XMLDoc = new XmlTextReader(MyString);

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

            bool done = false;
            while (!done && XMLDoc.Read())
            {
                switch (XMLDoc.NodeType)
                {
                    case XmlNodeType.Element:
                        LocalName = XMLDoc.LocalName;
                        switch (XMLDoc.LocalName)
                        {
                            case "dataType":
                                if (XMLDoc.HasAttributes)
                                {
                                    for (int i = 0; i < XMLDoc.AttributeCount; i++)
                                    {
                                        XMLDoc.MoveToAttribute(i);
                                        if (XMLDoc.LocalName == "type")
                                        {
                                            P[0] = XMLDoc.Value;
                                            if (P.DCOUNT() == 1)
                                            {
                                                ComplexType = P[1];
                                            }
                                            else
                                            {
                                                ComplexType = P[2];
                                                ComplexTypeNS = P[1];
                                            }
                                            CT = (UPnPComplexType)ComplexTypeTable[ComplexType + ":" + XMLDoc.LookupNamespace(ComplexTypeNS)];
                                        }
                                    }
                                }
                                break;
                            case "allowedValueList":
                                bool done2 = false;

                                while (!done2 && XMLDoc.Read())
                                {
                                    switch (XMLDoc.NodeType)
                                    {
                                        case XmlNodeType.Element:
                                            lname2 = XMLDoc.LocalName;
                                            break;
                                        case XmlNodeType.EndElement:
                                            if (XMLDoc.LocalName == "allowedValueList")
                                            {
                                                done2 = true;
                                            }
                                            break;
                                        case XmlNodeType.Text:
                                            if (lname2 == "allowedValue")
                                            {
                                                allowedValueList.Add(XMLDoc.Value);
                                            }
                                            break;
                                    }
                                }
                                break;
                            case "allowedValueRange":
                                bool done3 = false;

                                while (!done3 && XMLDoc.Read())
                                {
                                    switch (XMLDoc.NodeType)
                                    {
                                        case XmlNodeType.Element:
                                            lname2 = XMLDoc.LocalName;
                                            break;
                                        case XmlNodeType.EndElement:
                                            if (XMLDoc.LocalName == "allowedValueRange")
//.........这里部分代码省略.........
开发者ID:rvodden,项目名称:upnp-developertools-old,代码行数:101,代码来源:UPnPService.cs

示例3: ValidateXsiType

        // This method validates xsi:type="dcterms:W3CDTF"
        // The valude of xsi:type is a qualified name. It should have a prefix that matches 
        //  the xml namespace (ns) within the scope and the name that matches name
        // The comparisons should be case-sensitive comparisons
        internal static void ValidateXsiType(XmlTextReader reader, Object ns, string name)
        { 
            // Get the value of xsi;type
            String typeValue = reader.GetAttribute(PackageXmlStringTable.GetXmlString(PackageXmlEnum.Type), 
                                PackageXmlStringTable.GetXmlString(PackageXmlEnum.XmlSchemaInstanceNamespace)); 

            // Missing xsi:type 
            if (typeValue == null)
            {
                throw new XmlException(SR.Get(SRID.UnknownDCDateTimeXsiType, reader.Name),
                    null, reader.LineNumber, reader.LinePosition); 
            }
 
            int index = typeValue.IndexOf(':'); 

            // The valude of xsi:type is not a qualified name 
            if (index == -1)
            {
                throw new XmlException(SR.Get(SRID.UnknownDCDateTimeXsiType, reader.Name),
                    null, reader.LineNumber, reader.LinePosition); 
            }
 
            // Check the following conditions 
            //  The namespace of the prefix (string before ":") matches "ns"
            //  The name (string after ":") matches "name" 
            if (!Object.ReferenceEquals(ns, reader.LookupNamespace(typeValue.Substring(0, index)))
                    || String.CompareOrdinal(name, typeValue.Substring(index + 1, typeValue.Length - index - 1)) != 0)
            {
                throw new XmlException(SR.Get(SRID.UnknownDCDateTimeXsiType, reader.Name), 
                    null, reader.LineNumber, reader.LinePosition);
            } 
 

 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:39,代码来源:PartBasedPackageProperties.cs

示例4: ParseDevice


//.........这里部分代码省略.........
                                    Uri.TryCreate("http://" + u, UriKind.Absolute, out RetVal.ModelURL);
                                }
                            }
                            catch (Exception ex)
                            {
                                OpenSource.Utilities.EventLogger.Log(ex);
                            }
                            break;
                        case "serialNumber":
                            RetVal.SerialNumber = XMLDoc.ReadString();
                            break;
                        case "UDN":
                            TempString = XMLDoc.ReadString();
                            RetVal.UniqueDeviceName = TempString.Substring(5);
                            break;
                        case "UPC":
                            RetVal.ProductCode = XMLDoc.ReadString();
                            break;
                        case "presentationURL":
                            RetVal.HasPresentation = true;
                            RetVal.PresentationURL = XMLDoc.ReadString();
                            break;
                        case "serviceList":
                            if (XMLDoc.IsEmptyElement)
                                break;

                            XMLDoc.Read();
                            XMLDoc.MoveToContent();
                            while (XMLDoc.LocalName != "serviceList")
                            {
                                if (XMLDoc.LocalName == "service")
                                {
                                    embeddedLine = XMLDoc.LineNumber;
                                    service = UPnPService.Parse(XMLDoc.ReadOuterXml(), embeddedLine - 1 + startLine);
                                    RetVal.AddService(service);
                                }
                                if (!XMLDoc.IsStartElement())
                                {
                                    if (XMLDoc.LocalName != "serviceList")
                                    {
                                        XMLDoc.Read();
                                        XMLDoc.MoveToContent();
                                    }
                                }
                            }
                            break;

                        /*
                            case "iconList":
                                bool finishedIconList = false;
                                while (!finishedIconList && XMLDoc.Read())
                                {
                                    switch (XMLDoc.NodeType)
                                    {
                                        case XmlNodeType.Element:
                                            if (XMLDoc.LocalName == "icon")
                                            {
                                                embeddedLine = XMLDoc.LineNumber;
                                                ParseIconXML(RetVal, startLine + embeddedLine-1, XMLDoc.ReadOuterXml());
                                                if (XMLDoc.NodeType == XmlNodeType.EndElement && XMLDoc.LocalName == "iconList") { finishedIconList = true; }
                                            }
                                            break;
                                        case XmlNodeType.EndElement:
                                            if (XMLDoc.LocalName == "iconList") { finishedIconList = true; }
                                            break;
                                    }
                                }
                                break;
                            */

                        default:
                            if (XMLDoc.LocalName != "")
                            {
                                string customPrefix = XMLDoc.Prefix;
                                string customFieldName = XMLDoc.LocalName;
                                string customFieldNamespace = XMLDoc.LookupNamespace(customPrefix);
                                string customFieldVal = XMLDoc.ReadInnerXml();
                                RetVal.AddCustomFieldInDescription(customFieldName, customFieldVal, customFieldNamespace);
                            }
                            else
                            {
                                XMLDoc.Skip();
                            }
                            continue;
                        }

                        XMLDoc.Read();
                        //XMLDoc.MoveToContent();
                    }
                }
            }
            catch (XMLParsingException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new XMLParsingException("Invalid Device XML", startLine + XMLDoc.LineNumber, XMLDoc.LinePosition, ex);
            }
        }
开发者ID:genielabs,项目名称:intel-upnp-dlna,代码行数:101,代码来源:UPnPDevice.cs

示例5: ExpandNamespace

        private static string ExpandNamespace( XmlTextReader reader )
        {
            string propName = reader.Name;
            string propNamespace = reader.LookupNamespace( reader.Prefix );

            int namespaceBreak = propName.IndexOf( XmlNamespaceSeperator );

            string expandedName;

            if( namespaceBreak < 0 )
            {
                expandedName = propName;
            }
            else
            {
                expandedName = propNamespace + propName.Substring( namespaceBreak + 1 );
            }

            return( expandedName );
        }
开发者ID:markkimsal,项目名称:pengyou-clients,代码行数:20,代码来源:DavPropertyUtil.cs

示例6: ParseComplexType_SequenceChoice

        private static ItemCollection ParseComplexType_SequenceChoice(XmlTextReader X)
        {
            bool done = false;
            ItemCollection RetVal = null;
            string elementName = X.LocalName;
            DText p = new DText();
            p.ATTRMARK = ":";

            if (X.LocalName == "choice")
            {
                RetVal = new Choice();
            }
            else
            {
                RetVal = new Sequence();
            }

            if (X.HasAttributes)
            {
                for (int i = 0; i < X.AttributeCount; i++)
                {
                    X.MoveToAttribute(i);
                    switch (X.LocalName)
                    {
                    case "minOccurs":
                        RetVal.MinOccurs = X.Value;
                        break;
                    case "maxOccurs":
                        RetVal.MaxOccurs = X.Value;
                        break;
                    }
                }
                X.MoveToElement();
            }
            X.Read();

            do
            {
                switch (X.NodeType)
                {
                case XmlNodeType.Element:
                    switch (X.LocalName)
                    {
                    case "group":
                        if (X.HasAttributes)
                        {
                            for (int i = 0; i < X.AttributeCount; i++)
                            {
                                X.MoveToAttribute(i);
                                switch (X.LocalName)
                                {
                                case "ref":
                                    string sample = X.Value;
                                    break;
                                }
                            }
                            X.MoveToElement();
                        }
                        break;
                    case "sequence":
                    case "choice":
                        RetVal.AddCollection(ParseComplexType_SequenceChoice(X));
                        break;
                    case "element":
                        RetVal.AddContentItem(new Element());
                        if (X.HasAttributes)
                        {
                            for (int i = 0; i < X.AttributeCount; i++)
                            {
                                X.MoveToAttribute(i);
                                switch (X.LocalName)
                                {
                                case "name":
                                    RetVal.CurrentItem.Name = X.Value;
                                    break;
                                case "type":
                                    p[0] = X.Value;
                                    if (p.DCOUNT() == 1)
                                    {
                                        RetVal.CurrentItem.Type = X.Value;
                                        RetVal.CurrentItem.TypeNS = X.LookupNamespace("");
                                    }
                                    else
                                    {
                                        RetVal.CurrentItem.Type = p[2];
                                        RetVal.CurrentItem.TypeNS = X.LookupNamespace(p[1]);
                                    }
                                    break;
                                case "minOccurs":
                                    RetVal.CurrentItem.MinOccurs = X.Value;
                                    break;
                                case "maxOccurs":
                                    RetVal.CurrentItem.MaxOccurs = X.Value;
                                    break;
                                }
                            }
                            X.MoveToElement();
                        }
                        break;
                    case "attribute":
//.........这里部分代码省略.........
开发者ID:genielabs,项目名称:intel-upnp-dlna,代码行数:101,代码来源:UPnPComplexType.cs

示例7: ParseComplexType

        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;
//.........这里部分代码省略.........
开发者ID:genielabs,项目名称:intel-upnp-dlna,代码行数:101,代码来源:UPnPComplexType.cs

示例8: ParseDevice


//.........这里部分代码省略.........
                            break;
                        case "modelNumber":
                            RetVal.ModelNumber = XMLDoc.ReadString();
                            break;
                        case "modelURL":
                            try
                            {
                                string u = XMLDoc.ReadString();
                                if (Uri.TryCreate(u, UriKind.Absolute, out RetVal.ModelURL) == false) { Uri.TryCreate("http://" + u, UriKind.Absolute, out RetVal.ModelURL); }
                            }
                            catch { }
                            break;
                        case "serialNumber":
                            RetVal.SerialNumber = XMLDoc.ReadString();
                            break;
                        case "UDN":
                            TempString = XMLDoc.ReadString();
                            RetVal.UniqueDeviceName = TempString.Substring(5);
                            break;
                        case "UPC":
                            RetVal.ProductCode = XMLDoc.ReadString();
                            break;
                        case "presentationURL":
                            RetVal.HasPresentation = true;
                            RetVal.PresentationURL = XMLDoc.ReadString();
                            break;
                        case "serviceList":
                            if (XMLDoc.IsEmptyElement) break;

                            XMLDoc.Read();
                            XMLDoc.MoveToContent();
                            while (XMLDoc.LocalName != "serviceList")
                            {
                                if (XMLDoc.LocalName == "service")
                                {
                                    // TODO: DONE Resilience case 5a - wrap in try/catch block
                                    string servicexml = "Failed to read service xml element from device xml";
                                    try
                                    {
                                        servicexml = XMLDoc.ReadOuterXml();
                                        service = UPnPService.Parse(servicexml);
                                        RetVal.AddService(service);
                                    }
                                    catch (Exception e)
                                    {
                                        OpenSource.Utilities.EventLogger.Log(null, System.Diagnostics.EventLogEntryType.Error, "Invalid Service element within Device XML");
                                        OpenSource.Utilities.EventLogger.Log(e, "XML content: \r\n" + servicexml);
                                        OpenSource.Utilities.EventLogger.Log(null, System.Diagnostics.EventLogEntryType.Warning, "Dropping failed Service and commencing parsing remainder of device");
                                    }
                                }
                                if (!XMLDoc.IsStartElement())
                                {
                                    if (XMLDoc.LocalName != "serviceList")
                                    {
                                        XMLDoc.Read();
                                        XMLDoc.MoveToContent();
                                    }
                                }
                            }
                            break;
                        case "iconList":
                            bool finishedIconList = false;
                            while (!finishedIconList && XMLDoc.Read())
                            {
                                switch (XMLDoc.NodeType)
                                {
                                    case XmlNodeType.Element:
                                        if (XMLDoc.LocalName == "icon")
                                        {
                                            ParseIconXML(RetVal, XMLDoc.ReadOuterXml());
                                            if (XMLDoc.NodeType == XmlNodeType.EndElement && XMLDoc.LocalName == "iconList") { finishedIconList = true; }
                                        }
                                        break;
                                    case XmlNodeType.EndElement:
                                        if (XMLDoc.LocalName == "iconList") { finishedIconList = true; }
                                        break;
                                }
                            }
                            break;
                        default:
                            if (XMLDoc.LocalName != "")
                            {
                                string customPrefix = XMLDoc.Prefix;
                                string customFieldName = XMLDoc.LocalName;
                                string customFieldNamespace = XMLDoc.LookupNamespace(customPrefix);
                                string customFieldVal = XMLDoc.ReadInnerXml();
                                RetVal.AddCustomFieldInDescription(customFieldName, customFieldVal, customFieldNamespace);
                            }
                            else
                            {
                                XMLDoc.Skip();
                            }
                            continue;
                    }

                    XMLDoc.Read();
                    //XMLDoc.MoveToContent();
                }
            }
        }
开发者ID:Tieske,项目名称:Developer-Tools-for-UPnP-Technologies,代码行数:101,代码来源:UPnPDevice.cs

示例9: ReadType

        /// <summary>
        /// Reads the data type from an XML stream.
        /// </summary>
        private System.Type ReadType(XmlTextReader reader, string type)
        {
            bool   array         = false;
            string parsedType    = type;
            string typeNamespace = null;

            // extract namespace.
            int index = parsedType.IndexOf(":");

            if (index != -1)
            {
                typeNamespace = reader.LookupNamespace(parsedType.Substring(0, index));
                parsedType    = parsedType.Substring(index+1);
            }

            // remove array prefix.
            if (type.StartsWith(ARRAY_OF))
            {
                parsedType = type.Substring(ARRAY_OF.Length, 1).ToLower() + type.Substring(ARRAY_OF.Length+1);
                array      = true;
            }

            // check for standard types.
            if (parsedType == "byte")          return (array)?typeof(sbyte[]):typeof(sbyte);
            if (parsedType == "unsignedByte")  return (array)?typeof(byte[]):typeof(byte);
            if (parsedType == "short")         return (array)?typeof(short[]):typeof(short);
            if (parsedType == "unsignedShort") return (array)?typeof(ushort[]):typeof(ushort);
            if (parsedType == "int")           return (array)?typeof(int[]):typeof(int);
            if (parsedType == "unsignedInt")   return (array)?typeof(uint[]):typeof(uint);
            if (parsedType == "long")          return (array)?typeof(long[]):typeof(long);
            if (parsedType == "unsignedLong")  return (array)?typeof(ulong[]):typeof(ulong);
            if (parsedType == "float")         return (array)?typeof(float[]):typeof(float);
            if (parsedType == "double")        return (array)?typeof(double[]):typeof(double);
            if (parsedType == "decimal")       return (array)?typeof(decimal[]):typeof(decimal);
            if (parsedType == "string")        return (array)?typeof(string[]):typeof(string);
            if (parsedType == "boolean")       return (array)?typeof(bool[]):typeof(bool);
            if (parsedType == "dateTime")      return (array)?typeof(DateTime[]):typeof(DateTime);
            if (parsedType == "anyType")       return (array)?typeof(object[]):typeof(object);
            if (parsedType == "hexBinary")     return (array)?typeof(string[]):typeof(string);

            // unsupported xml schema defined data type.
            if (typeNamespace == Opc.Namespace.XML_SCHEMA)
            {
                return null;
            }

            // must be complex type.
            return typeof(object[]);
        }
开发者ID:AymanShawky,项目名称:niko78csharp,代码行数:52,代码来源:Opc.Da.DeviceItem.cs


注:本文中的System.Xml.XmlTextReader.LookupNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。