本文整理汇总了C#中IXmlNamespaceResolver.LookupNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# IXmlNamespaceResolver.LookupNamespace方法的具体用法?C# IXmlNamespaceResolver.LookupNamespace怎么用?C# IXmlNamespaceResolver.LookupNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IXmlNamespaceResolver
的用法示例。
在下文中一共展示了IXmlNamespaceResolver.LookupNamespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
internal static XmlQualifiedName Parse(string s, IXmlNamespaceResolver nsmgr, out string prefix)
{
string localName;
ValidateNames.ParseQNameThrow(s, out prefix, out localName);
string uri = nsmgr.LookupNamespace(prefix);
if (uri == null)
{
if (prefix.Length != 0)
{
throw new XmlException(SR.Xml_UnknownNs, prefix);
}
else
{ //Re-map namespace of empty prefix to string.Empty when there is no default namespace declared
uri = string.Empty;
}
}
return new XmlQualifiedName(localName, uri);
}
示例2: XmlWellFormedWriter
//
// Constructor & finalizer
//
internal XmlWellFormedWriter(XmlWriter writer, XmlWriterSettings settings)
{
Debug.Assert(writer != null);
Debug.Assert(settings != null);
Debug.Assert(MaxNamespacesWalkCount <= 3);
_writer = writer;
_rawWriter = writer as XmlRawWriter;
_predefinedNamespaces = writer as IXmlNamespaceResolver;
if (_rawWriter != null)
{
_rawWriter.NamespaceResolver = new NamespaceResolverProxy(this);
}
_checkCharacters = settings.CheckCharacters;
_omitDuplNamespaces = (settings.NamespaceHandling & NamespaceHandling.OmitDuplicates) != 0;
_writeEndDocumentOnClose = settings.WriteEndDocumentOnClose;
_conformanceLevel = settings.ConformanceLevel;
_stateTable = (_conformanceLevel == ConformanceLevel.Document) ? s_stateTableDocument : s_stateTableAuto;
_currentState = State.Start;
_nsStack = new Namespace[NamespaceStackInitialSize];
_nsStack[0].Set("xmlns", XmlReservedNs.NsXmlNs, NamespaceKind.Special);
_nsStack[1].Set("xml", XmlReservedNs.NsXml, NamespaceKind.Special);
if (_predefinedNamespaces == null)
{
_nsStack[2].Set(string.Empty, string.Empty, NamespaceKind.Implied);
}
else
{
string defaultNs = _predefinedNamespaces.LookupNamespace(string.Empty);
_nsStack[2].Set(string.Empty, (defaultNs == null ? string.Empty : defaultNs), NamespaceKind.Implied);
}
_nsTop = 2;
_elemScopeStack = new ElementScope[ElementStackInitialSize];
_elemScopeStack[0].Set(string.Empty, string.Empty, string.Empty, _nsTop);
_elemScopeStack[0].xmlSpace = XmlSpace.None;
_elemScopeStack[0].xmlLang = null;
_elemTop = 0;
_attrStack = new AttrName[AttributeArrayInitialSize];
_hasher = new SecureStringHasher();
}
示例3: StringToQName
private static XmlQualifiedName StringToQName(string value, IXmlNamespaceResolver nsResolver)
{
string prefix, localName, ns;
value = value.Trim();
// Parse prefix:localName
try
{
ValidateNames.ParseQNameThrow(value, out prefix, out localName);
}
catch (XmlException e)
{
throw new FormatException(e.Message);
}
// Throw error if no namespaces are in scope
if (nsResolver == null)
throw new InvalidCastException(SR.Format(SR.XmlConvert_TypeNoNamespace, value, prefix));
// Lookup namespace
ns = nsResolver.LookupNamespace(prefix);
if (ns == null)
throw new InvalidCastException(SR.Format(SR.XmlConvert_TypeNoNamespace, value, prefix));
// Create XmlQualfiedName
return new XmlQualifiedName(localName, ns);
}
示例4: ParseQName
// Methods
public static XmlQualifiedName ParseQName (string name, IXmlNamespaceResolver resolver)
{
int index = name.IndexOf (':');
if (index < 0)
return new XmlQualifiedName (name);
string ns = resolver.LookupNamespace (name.Substring (0, index));
if (ns == null)
throw new ArgumentException ("Invalid qualified name.");
return new XmlQualifiedName (name.Substring (index + 1), ns);
}
示例5: Parse
internal static XmlQualifiedName Parse (string name, IXmlNamespaceResolver resolver, bool considerDefaultNamespace)
{
int index = name.IndexOf (':');
if (index < 0 && !considerDefaultNamespace)
return new XmlQualifiedName (name);
string prefix = index < 0 ? String.Empty : name.Substring (0, index);
string localName = index < 0 ? name : name.Substring (index + 1);
string ns = resolver.LookupNamespace (prefix);
if (ns == null) {
if (prefix.Length > 0)
throw new ArgumentException ("Invalid qualified name.");
else
ns = String.Empty;
}
return new XmlQualifiedName (localName, ns);
}
示例6: XmlAtomicValue
internal XmlAtomicValue(XmlSchemaType xmlType, string value, IXmlNamespaceResolver nsResolver)
{
if (value == null) throw new ArgumentNullException(nameof(value));
if (xmlType == null) throw new ArgumentNullException(nameof(xmlType));
_xmlType = xmlType;
_objVal = value;
if (nsResolver != null && (_xmlType.TypeCode == XmlTypeCode.QName || _xmlType.TypeCode == XmlTypeCode.Notation))
{
string prefix = GetPrefixFromQName(value);
_nsPrefix = new NamespacePrefixForQName(prefix, nsResolver.LookupNamespace(prefix));
}
}
示例7: GenerateNewElement
private static XElement GenerateNewElement(string name, IXmlNamespaceResolver resolver)
{
XName newElementName = null;
if (name.Contains(XPathExtensions.namespaceSeparator))
{
if (resolver == null) throw new ArgumentNullException("resolver", "Es wurde keine NamespaceResolver angegeben.");
var splittedName = name.Split(new [] { XPathExtensions.namespaceSeparator }, StringSplitOptions.None);
var namespacePraefix = splittedName.Length > 1 ? splittedName[0] : string.Empty;
var elementName = splittedName.Length > 1 ? splittedName[1] : splittedName[0];
XNamespace nameSpace = resolver.LookupNamespace(namespacePraefix);
if (string.IsNullOrEmpty(nameSpace.NamespaceName))
{
throw new InvalidOperationException(string.Format("Es wurde kein Nampespace mit dem Präfix \"{0}\" gefunden.", namespacePraefix));
}
newElementName = nameSpace + elementName;
}
else
{
if(resolver != null)
{
throw new XPathException("Das Element konnte nicht erstellt werden. Es fehlt ein entsprechender Namespace im Pfad.");
}
newElementName = name;
}
// Neues Element wird erstellt
return new XElement(newElementName);
}
示例8: Matches
public override bool Matches(XmlReader reader, IXmlNamespaceResolver resolver)
{
bool nsMatches = IsAnyNamespace;
bool nameMatches = IsAnyName;
if (!nsMatches)
{
string ns = String.Empty;
if (prefix.Length > 0)
{
if (resolver == null)
{
throw new ArgumentException(Properties.Resources.NamespaceResolverRequired, "resolver");
}
ns = resolver.LookupNamespace(prefix);
if (ns == null)
{
throw new ArgumentException(String.Format(
CultureInfo.CurrentCulture,
Properties.Resources.CannotResolvePrefix,
prefix));
}
}
nsMatches = (ns == reader.NamespaceURI);
}
if (!nameMatches)
{
nameMatches = (name == reader.LocalName);
}
return nsMatches && nameMatches;
}
示例9: Parse
internal static XmlQualifiedName Parse(string s, IXmlNamespaceResolver nsmgr, out string prefix)
{
string str;
ValidateNames.ParseQNameThrow(s, out prefix, out str);
string ns = nsmgr.LookupNamespace(prefix);
if (ns == null)
{
if (prefix.Length != 0)
{
throw new XmlException("Xml_UnknownNs", prefix);
}
ns = string.Empty;
}
return new XmlQualifiedName(str, ns);
}
示例10: ParseQName
// Parse a QName from the string, and resolve prefix
XmlQualifiedName ParseQName(string xpath, ref int pos, IXmlNamespaceResolver xnr) {
string nm = ParseName(xpath, ref pos);
if (pos < xpath.Length && ':' == xpath[pos]) {
pos++;
string ns = (null==xnr) ? null : xnr.LookupNamespace(nm);
if (null == ns || 0 == ns.Length)
throw new XmlException(Res.Sch_UnresolvedPrefix, nm);
return new XmlQualifiedName(ParseName(xpath, ref pos), ns);
}
else {
return new XmlQualifiedName(nm);
}
}
示例11: XmlAtomicValue
internal XmlAtomicValue(XmlSchemaType xmlType, string value, IXmlNamespaceResolver nsResolver)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
if (xmlType == null)
{
throw new ArgumentNullException("xmlType");
}
this.xmlType = xmlType;
this.objVal = value;
if ((nsResolver != null) && ((this.xmlType.TypeCode == XmlTypeCode.QName) || (this.xmlType.TypeCode == XmlTypeCode.Notation)))
{
string prefixFromQName = this.GetPrefixFromQName(value);
this.nsPrefix = new NamespacePrefixForQName(prefixFromQName, nsResolver.LookupNamespace(prefixFromQName));
}
}
示例12: Clean
//.........这里部分代码省略.........
foreach (var item in items.Where(e => !e.IsEmpty && !e.HasElements))
{
item.RemoveNodes();
}
#endregion
#region Clean up References
proj.XPathSelectElements("//build:Reference[@Include='System.configuration']", ns).Attributes("Include").SetValue("System.Configuration");
proj.XPathSelectElements("//build:Reference[@Include='System.XML']", ns).Attributes("Include").SetValue("System.Xml");
proj.XPathSelectElements("//build:AssemblyFolderKey", ns).Remove();
proj.XPathSelectElements("//build:SpecificVersion", ns).Remove();
proj.XPathSelectElements("//build:ReferencePath", ns).Remove();
proj.XPathSelectElements("//build:CurrentPlatform", ns).Remove();
proj.XPathSelectElements("//build:Reference/build:Name", ns).Remove();
proj.XPathSelectElements("//build:Reference/build:RequiredTargetFramework", ns).Remove();
var referenceParent = proj.XPathSelectElements("//build:ItemGroup[build:Reference]", ns).FirstOrDefault();
if (referenceParent != null)
{
proj.XPathSelectElements("//build:Reference", ns).OrderBy(c => c.Attribute("Include").Value.SubstringTill(',').Replace("System", "aaaaaaa")).Reparent(referenceParent);
}
#endregion
#region Clean up ProjectReferences
proj.XPathSelectElements("//build:ProjectReference/build:Package", ns).Remove();
proj.XPathSelectElements("//build:ProjectReference[@Include]/build:Name", ns).SetValue(n => Path.GetFileNameWithoutExtension(n.Parent.Attribute("Include").Value));
foreach (var name in proj.XPathSelectElements("//build:ProjectReference[@Include]/build:Name", ns))
{
var parent = name.Parent;
name.Remove();
parent.AddFirst(name);
}
var projectReferenceParent = proj.XPathSelectElements("//build:ItemGroup[build:ProjectReference]", ns).FirstOrDefault();
if (projectReferenceParent != null)
{
proj.XPathSelectElements("//build:ProjectReference", ns).OrderBy(c => c.Element(XName.Get("Name", ns.LookupNamespace("build"))).Value).Reparent(projectReferenceParent);
}
var imports = proj.XPathSelectElements("//build:Import[starts-with(@Project, '..')]", ns).ToArray();
foreach (var import in imports)
{
var path = import.Attribute("Project").Value;
import.SetAttributeValue("Condition", String.Format("Exists('{0}')", path));
continue;
}
#endregion
#region Clean up Web Projects
proj.XPathSelectElements("//build:SaveServerSettingsInUserFile", ns).SetValue(true);
proj.XPathSelectElements("//build:WebProjectProperties/build:UseIIS", ns).Remove();
proj.XPathSelectElements("//build:WebProjectProperties/build:AutoAssignPort", ns).Remove();
proj.XPathSelectElements("//build:WebProjectProperties/build:DevelopmentServerPort", ns).Remove();
proj.XPathSelectElements("//build:WebProjectProperties/build:DevelopmentServerVPath", ns).Remove();
proj.XPathSelectElements("//build:WebProjectProperties/build:IISUrl", ns).Remove();
proj.XPathSelectElements("//build:WebProjectProperties/build:NTLMAuthentication", ns).Remove();
proj.XPathSelectElements("//build:WebProjectProperties/build:UseCustomServer", ns).Remove();
proj.XPathSelectElements("//build:WebProjectProperties/build:CustomServerUrl", ns).Remove();
#endregion
#region Clean up PreBuildEvent/PostBuildEvent
proj.XPathSelectElements("//build:PostBuildEvent", ns).Where(e => e.Value.IndexOf("sn.exe", StringComparison.CurrentCultureIgnoreCase) >= 0).SetValue("");
proj.XPathSelectElements("//build:PreBuildEvent", ns).Where(e => String.IsNullOrWhiteSpace(e.Value)).Remove();
proj.XPathSelectElements("//build:PostBuildEvent", ns).Where(e => String.IsNullOrWhiteSpace(e.Value)).Remove();
if (!proj.XPathSelectElements("//build:PreBuildEvent", ns).Any(e => String.IsNullOrWhiteSpace(e.Value)))
proj.XPathSelectElements("//build:RunPreBuildEvent", ns).Remove();
if (!proj.XPathSelectElements("//build:PostBuildEvent", ns).Any(e => String.IsNullOrWhiteSpace(e.Value)))
proj.XPathSelectElements("//build:RunPostBuildEvent", ns).Remove();
#endregion
#region Configure signing
var canSign = !String.IsNullOrEmpty(relativeSigningKeyPath);
proj.XPathSelectElements("//build:SignAssembly", ns).Remove();
proj.XPathSelectElements("//build:DelaySign", ns).Remove();
proj.XPathSelectElements("//build:AssemblyOriginatorKeyFile", ns).Remove();
proj.XPathSelectElements("//build:AssemblyKeyContainerName", ns).Remove();
if (mainPG != null)
{
mainPG.AddElement("SignAssembly", content: canSign);
if (canSign)
{
mainPG.AddElement("DelaySign", content: false);
mainPG.AddElement("AssemblyOriginatorKeyFile", content: relativeSigningKeyPath);
}
}
#endregion
proj.XPathSelectElements("//build:PropertyGroup", ns).Where(e => !e.Nodes().Any()).Remove();
proj.XPathSelectElements("//build:ItemGroup", ns).Where(e => !e.Nodes().Any()).Remove();
}
示例13: XmlWellFormedWriter
//
// Constructor & finalizer
//
internal XmlWellFormedWriter(XmlWriter writer, XmlWriterSettings settings) {
Debug.Assert(writer != null);
Debug.Assert(settings != null);
Debug.Assert(MaxNamespacesWalkCount <= 3);
this.writer = writer;
rawWriter = writer as XmlRawWriter;
predefinedNamespaces = writer as IXmlNamespaceResolver;
if (rawWriter != null) {
rawWriter.NamespaceResolver = new NamespaceResolverProxy(this);
}
checkCharacters = settings.CheckCharacters;
conformanceLevel = settings.ConformanceLevel;
stateTable = (conformanceLevel == ConformanceLevel.Document) ? StateTableDocument : StateTableAuto;
currentState = State.Start;
nsStack = new Namespace[NamespaceStackInitialSize];
nsStack[0].Set("xmlns", XmlReservedNs.NsXmlNs, NamespaceKind.Special);
nsStack[1].Set("xml", XmlReservedNs.NsXml, NamespaceKind.Special);
if (predefinedNamespaces == null) {
nsStack[2].Set(string.Empty, string.Empty, NamespaceKind.Implied);
}
else {
string defaultNs = predefinedNamespaces.LookupNamespace(string.Empty);
nsStack[2].Set(string.Empty, (defaultNs == null ? string.Empty : defaultNs), NamespaceKind.Implied);
}
nsTop = 2;
elemScopeStack = new ElementScope[ElementStackInitialSize];
elemScopeStack[0].Set(string.Empty, string.Empty, string.Empty, nsTop);
elemScopeStack[0].xmlSpace = XmlSpace.None;
elemScopeStack[0].xmlLang = null;
elemTop = 0;
attrStack = new AttrName[AttributeArrayInitialSize];
attrValue = new StringBuilder();
hasher = new SecureStringHasher();
}
示例14: StringToQName
protected static XmlQualifiedName StringToQName(string value, IXmlNamespaceResolver nsResolver)
{
string str;
string str2;
value = value.Trim();
try
{
ValidateNames.ParseQNameThrow(value, out str, out str2);
}
catch (XmlException exception)
{
throw new FormatException(exception.Message);
}
if (nsResolver == null)
{
throw new InvalidCastException(Res.GetString("XmlConvert_TypeNoNamespace", new object[] { value, str }));
}
string ns = nsResolver.LookupNamespace(str);
if (ns == null)
{
throw new InvalidCastException(Res.GetString("XmlConvert_TypeNoNamespace", new object[] { value, str }));
}
return new XmlQualifiedName(str2, ns);
}
示例15: SelectInternal
private IEnumerable<XObject> SelectInternal(string path, IXmlNamespaceResolver manager)
{
if (path.StartsWith("/"))
{
path = path.Substring(1);
}
var nodes = (IEnumerable<XObject>) new[] {_obj};
foreach (var part in path.Split('/'))
{
if (part == "*")
{
nodes = nodes.Cast<XContainer>().Elements();
}
else if (part == "")
{
nodes = nodes.Cast<XContainer>().Descendants();
}
else
{
var isAttribute = part.StartsWith("@");
var str = isAttribute ? part.Substring(1) : part;
var pos = str.IndexOf(":", StringComparison.Ordinal);
var name = pos >= 0
? XName.Get(str.Substring(pos + 1), manager.LookupNamespace(str.Substring(0, pos)))
: XName.Get(str);
if (isAttribute)
{
nodes = nodes.Cast<XElement>().Attributes(name);
}
else
{
nodes = nodes.Cast<XContainer>().Elements(name);
}
}
}
return nodes;
}