本文整理匯總了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);
}
示例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")
//.........這裏部分代碼省略.........
示例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);
}
}
示例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);
}
}
示例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 );
}
示例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":
//.........這裏部分代碼省略.........
示例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;
//.........這裏部分代碼省略.........
示例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();
}
}
}
示例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[]);
}