本文整理汇总了C#中System.Xml.XmlNamespaceManager.GetNamespacesInScope方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNamespaceManager.GetNamespacesInScope方法的具体用法?C# XmlNamespaceManager.GetNamespacesInScope怎么用?C# XmlNamespaceManager.GetNamespacesInScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlNamespaceManager
的用法示例。
在下文中一共展示了XmlNamespaceManager.GetNamespacesInScope方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValue
public string GetValue(XElement element, XmlNamespaceManager nsm)
{
XPathContext context = new XPathContext((NameTable)nsm.NameTable);
XPathNavigator navigator = element.CreateNavigator();
object result = null;
foreach (var ns in nsm.GetNamespacesInScope(XmlNamespaceScope.All))
context.AddNamespace(ns.Key, ns.Value);
context.Arguments.AddParam(XPathContext.ParameterNames.CurrentNode, string.Empty, navigator.Select("."));
result = navigator.Evaluate(this.RawValue, context);
if (result is string)
return (string)result;
else if (result is XPathNodeIterator)
{
var iterator = ((XPathNodeIterator)result);
var current = (XPathNavigator)((IEnumerable)iterator).Cast<object>().First();
return current.Value;
}
else if (result is XAttribute)
return ((XAttribute)result).Value;
else if (result is XElement)
return ((XElement)result).Value;
return string.Empty;
}
示例2: Strip
public XmlNode Strip(XmlNode documentElement)
{
var namespaceManager = new XmlNamespaceManager(documentElement.OwnerDocument.NameTable);
foreach (var nspace in namespaceManager.GetNamespacesInScope(XmlNamespaceScope.All))
{
namespaceManager.RemoveNamespace(nspace.Key, nspace.Value);
}
return documentElement;
}
示例3: ImportResults
public FeatureCollectionResult ImportResults(IOpenSearchResultCollection results)
{
if (results == null)
throw new ArgumentNullException("results");
FeatureCollectionResult fc = new FeatureCollectionResult();
fc.Properties = new Dictionary<string, object>();
NameValueCollection namespaces = null;
XmlNamespaceManager xnsm = null;
string prefix = "";
List<XmlElement> elements = new List<XmlElement>();
foreach (var element in results.ElementExtensions) {
elements.Add(element.GetObject<XmlElement>());
}
if (options.KeepNamespaces) {
// Initialize namespaces
namespaces = new NameValueCollection();
namespaces.Set("", "http://geojson.org/ns#");
namespaces.Set("atom", "http://www.w3.org/2005/Atom");
foreach (var elem in results.ElementExtensions) {
XmlReader reader = elem.GetReader();
XmlDocument doc = new XmlDocument();
doc.Load(reader);
xnsm = new XmlNamespaceManager(doc.NameTable);
foreach (var names in xnsm.GetNamespacesInScope(XmlNamespaceScope.All)) {
namespaces.Set(names.Key, names.Value);
}
}
fc.Properties.Add("@namespaces", namespaces);
prefix = "atom:";
}
fc.Properties = fc.Properties.Concat(util.ImportXmlDocument(elements.ToArray(), ref namespaces)).ToDictionary(x => x.Key, x => x.Value);
if (results.Date != null && fc.Properties.ContainsKey(prefix + "updated") == null)
fc.Properties.Add(prefix + "updated", results.Date.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"));
if (results.Links != null && results.Links.Count > 0) {
fc.Links = results.Links;
}
if (options.KeepNamespaces == true && fc.Properties.ContainsKey("dc:identifier") == null) {
namespaces.Set("dc", "http://purl.org/dc/elements/1.1/");
fc.Properties.Add("dc:identifier", results.Identifier);
}
if (options.KeepNamespaces == false && fc.Properties.ContainsKey("identifier") == null) {
fc.Properties.Add("identifier", results.Identifier);
}
if (results.Items != null) {
foreach (var item in results.Items) {
fc.FeatureResults.Add(ImportItem(item));
}
}
return fc;
}
示例4: GetNamespacesInScope
public void GetNamespacesInScope ()
{
XmlNamespaceManager nsmgr =
new XmlNamespaceManager (new NameTable ());
Assert.AreEqual (0, nsmgr.GetNamespacesInScope (l).Count, "#1");
Assert.AreEqual (0, nsmgr.GetNamespacesInScope (x).Count, "#2");
Assert.AreEqual (1, nsmgr.GetNamespacesInScope (a).Count, "#3");
nsmgr.AddNamespace ("foo", "urn:foo");
Assert.AreEqual (1, nsmgr.GetNamespacesInScope (l).Count, "#4");
Assert.AreEqual (1, nsmgr.GetNamespacesInScope (x).Count, "#5");
Assert.AreEqual (2, nsmgr.GetNamespacesInScope (a).Count, "#6");
// default namespace
nsmgr.AddNamespace ("", "urn:empty");
Assert.AreEqual (2, nsmgr.GetNamespacesInScope (l).Count, "#7");
Assert.AreEqual (2, nsmgr.GetNamespacesInScope (x).Count, "#8");
Assert.AreEqual (3, nsmgr.GetNamespacesInScope (a).Count, "#9");
// PushScope
nsmgr.AddNamespace ("foo", "urn:foo");
nsmgr.PushScope ();
Assert.AreEqual (0, nsmgr.GetNamespacesInScope (l).Count, "#10");
Assert.AreEqual (2, nsmgr.GetNamespacesInScope (x).Count, "#11");
Assert.AreEqual (3, nsmgr.GetNamespacesInScope (a).Count, "#12");
// PopScope
nsmgr.PopScope ();
Assert.AreEqual (2, nsmgr.GetNamespacesInScope (l).Count, "#13");
Assert.AreEqual (2, nsmgr.GetNamespacesInScope (x).Count, "#14");
Assert.AreEqual (3, nsmgr.GetNamespacesInScope (a).Count, "#15");
nsmgr.AddNamespace ("", "");
// MS bug - it should return 1 for .Local but it returns 2 instead.
//Assert.AreEqual (1, nsmgr.GetNamespacesInScope (l).Count, "#16");
Assert.AreEqual (1, nsmgr.GetNamespacesInScope (x).Count, "#17");
Assert.AreEqual (2, nsmgr.GetNamespacesInScope (a).Count, "#18");
}
示例5: GetNamespacesInScope
public void GetNamespacesInScope ()
{
XmlNamespaceManager nsmgr =
new XmlNamespaceManager (new NameTable ());
AssertEquals (0, nsmgr.GetNamespacesInScope (l).Count);
AssertEquals (0, nsmgr.GetNamespacesInScope (x).Count);
AssertEquals (1, nsmgr.GetNamespacesInScope (a).Count);
nsmgr.AddNamespace ("foo", "urn:foo");
AssertEquals (1, nsmgr.GetNamespacesInScope (l).Count);
AssertEquals (1, nsmgr.GetNamespacesInScope (x).Count);
AssertEquals (2, nsmgr.GetNamespacesInScope (a).Count);
// default namespace
nsmgr.AddNamespace ("", "urn:empty");
AssertEquals (1, nsmgr.GetNamespacesInScope (l).Count);
AssertEquals (1, nsmgr.GetNamespacesInScope (x).Count);
AssertEquals (2, nsmgr.GetNamespacesInScope (a).Count);
// PushScope
nsmgr.AddNamespace ("foo", "urn:foo");
nsmgr.PushScope ();
AssertEquals (0, nsmgr.GetNamespacesInScope (l).Count);
AssertEquals (1, nsmgr.GetNamespacesInScope (x).Count);
AssertEquals (2, nsmgr.GetNamespacesInScope (a).Count);
// PopScope
nsmgr.PopScope ();
AssertEquals (1, nsmgr.GetNamespacesInScope (l).Count);
AssertEquals (1, nsmgr.GetNamespacesInScope (x).Count);
AssertEquals (2, nsmgr.GetNamespacesInScope (a).Count);
nsmgr.AddNamespace ("", "");
AssertEquals (1, nsmgr.GetNamespacesInScope (l).Count);
AssertEquals (1, nsmgr.GetNamespacesInScope (x).Count);
AssertEquals (2, nsmgr.GetNamespacesInScope (a).Count);
}
示例6: Namespaces
/// <summary>
/// Get namespaces.
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
public static IEnumerable<Tuple<string, string>> Namespaces(this XmlDocument document)
{
var manager = new XmlNamespaceManager(document.NameTable);
var ns = manager.GetNamespacesInScope(XmlNamespaceScope.All);
return ns.Select(x => new Tuple<string, string>(x.Key, x.Value));
}
示例7: ImportFeed
public FeatureCollectionResult ImportFeed(SyndicationFeed feed)
{
if (feed == null)
throw new ArgumentNullException("feed");
FeatureCollectionResult fc = new FeatureCollectionResult();
NameValueCollection namespaces = null;
XmlNamespaceManager xnsm = null;
string prefix = "";
if (options.KeepNamespaces) {
// Initialize namespaces
namespaces = new NameValueCollection();
namespaces.Set("", "http://geojson.org/ns#");
namespaces.Set("atom", "http://www.w3.org/2005/Atom");
XmlReader reader = feed.ElementExtensions.GetReaderAtElementExtensions();
xnsm = new XmlNamespaceManager(reader.NameTable);
foreach (var names in xnsm.GetNamespacesInScope(XmlNamespaceScope.All)) {
namespaces.Set(names.Key, names.Value);
}
fc.Properties.Add("@namespaces", namespaces);
prefix = "atom:";
}
// Import Feed
if (feed != null) {
if ((feed.Authors != null) && (feed.Authors.Count > 0)) {
object[] authors = new object[feed.Authors.Count];
fc.Properties.Add(prefix + "authors", authors);
for (int i = 0; i < feed.Authors.Count; i++) {
Dictionary<string,object> author = new Dictionary<string, object>();
author.Add(prefix + "name", feed.Authors[i].Name);
author.Add(prefix + "email", feed.Authors[i].Email);
author.Add(prefix + "uri", feed.Authors[i].Uri);
author = author.Concat(util.ImportAttributeExtensions(feed.Authors[i].AttributeExtensions, namespaces, xnsm)).ToDictionary(x => x.Key, x => x.Value);
author = author.Concat(util.ImportElementExtensions(feed.Authors[i].ElementExtensions, namespaces)).ToDictionary(x => x.Key, x => x.Value);
authors[i] = author;
}
}
if (feed.BaseUri != null) {
fc.Properties.Add(prefix + "uri", feed.BaseUri.ToString());
}
if ((feed.Categories != null) && (feed.Categories.Count > 0)) {
object[] categories = new object[feed.Categories.Count];
fc.Properties.Add(prefix + "categories", categories);
for (int i = 0; i < feed.Categories.Count; i++) {
Dictionary<string,object> category = new Dictionary<string, object>();
category.Add(prefix + "name", feed.Categories[i].Name);
category.Add(prefix + "label", feed.Categories[i].Label);
category.Add(prefix + "scheme", feed.Categories[i].Scheme);
category = category.Union(util.ImportAttributeExtensions(feed.Categories[i].AttributeExtensions, namespaces, xnsm)).ToDictionary(x => x.Key, x => x.Value);
category = category.Union(util.ImportElementExtensions(feed.Categories[i].ElementExtensions, namespaces)).ToDictionary(x => x.Key, x => x.Value);
categories[i] = category;
}
}
if ((feed.Contributors != null) && (feed.Contributors.Count > 0)) {
object[] contributors = new object[feed.Contributors.Count];
fc.Properties.Add(prefix + "categories", contributors);
for (int i = 0; i < feed.Contributors.Count; i++) {
Dictionary<string,object> contributor = new Dictionary<string, object>();
contributor.Add(prefix + "name", feed.Contributors[i].Name);
contributor.Add(prefix + "email", feed.Contributors[i].Email);
contributor.Add(prefix + "uri", feed.Contributors[i].Uri);
contributor = contributor.Union(util.ImportAttributeExtensions(feed.Contributors[i].AttributeExtensions, namespaces, xnsm)).ToDictionary(x => x.Key, x => x.Value);
contributor = contributor.Union(util.ImportElementExtensions(feed.Contributors[i].ElementExtensions, namespaces)).ToDictionary(x => x.Key, x => x.Value);
contributors[i] = contributor;
}
}
if (feed.Copyright != null) {
fc.Properties.Add(prefix + "rights", feed.Copyright.Text);
}
if (feed.Description != null) {
fc.Properties.Add(prefix + "content", feed.Description.Text);
}
if (feed.Generator != null) {
fc.Properties.Add(prefix + "generator", feed.Generator);
}
fc.Properties.Add(prefix + "id", feed.Id);
if (feed.ImageUrl != null)
fc.Properties.Add(prefix + "logo", feed.ImageUrl.ToString());
if (feed.Language != null)
fc.Properties.Add(prefix + "language", feed.Language);
if (feed.LastUpdatedTime != null)
fc.Properties.Add(prefix + "updated", feed.LastUpdatedTime);
if ((feed.Links != null) && (feed.Links.Count > 0)) {
fc.Links = feed.Links;
}
if (feed.Title != null)
fc.Properties.Add(prefix + "title", feed.Title);
if (feed.Items != null) {
foreach (var item in feed.Items) {
fc.FeatureResults.Add(ImportItem(item));
}
}
return fc;
//.........这里部分代码省略.........
示例8: ImportItem
public FeatureResult ImportItem(SyndicationItem item)
{
if (item != null) {
List<XmlElement> elements = new List<XmlElement>();
foreach (var element in item.ElementExtensions) {
elements.Add(element.GetObject<XmlElement>());
}
XmlElement geometry = ImportUtils.FindGmlGeometry(elements.ToArray());
FeatureResult feature = new FeatureResult(Terradue.GeoJson.Geometry.GeometryFactory.GmlToFeature(geometry));
NameValueCollection namespaces = null;
XmlNamespaceManager xnsm = null;
string prefix = "";
if (options.KeepNamespaces) {
// Initialize namespaces
namespaces = new NameValueCollection();
namespaces.Set("", "http://geojson.org/ns#");
namespaces.Set("atom", "http://www.w3.org/2005/Atom");
XmlReader reader = item.ElementExtensions.GetReaderAtElementExtensions();
xnsm = new XmlNamespaceManager(reader.NameTable);
foreach (var names in xnsm.GetNamespacesInScope(XmlNamespaceScope.All)) {
namespaces.Set(names.Key, names.Value);
}
feature.Properties.Add("@namespaces", namespaces);
prefix = "atom:";
}
// Import Item
if ((item.Authors != null) && (item.Authors.Count > 0)) {
object[] authors = new object[item.Authors.Count];
feature.Properties.Add(prefix + "authors", authors);
for (int i = 0; i < item.Authors.Count; i++) {
Dictionary<string,object> author = new Dictionary<string, object>();
author.Add(prefix + "name", item.Authors[i].Name);
author.Add(prefix + "email", item.Authors[i].Email);
author.Add(prefix + "uri", item.Authors[i].Uri);
author = author.Union(util.ImportAttributeExtensions(item.Authors[i].AttributeExtensions, namespaces, xnsm)).ToDictionary(x => x.Key, x => x.Value);
author = author.Union(util.ImportElementExtensions(item.Authors[i].ElementExtensions, namespaces)).ToDictionary(x => x.Key, x => x.Value);
authors[i] = author;
}
}
if (item.BaseUri != null) {
feature.Properties.Add(prefix + "uri", item.BaseUri.ToString());
}
if ((item.Categories != null) && (item.Categories.Count > 0)) {
object[] categories = new object[item.Categories.Count];
feature.Properties.Add(prefix + "categories", categories);
for (int i = 0; i < item.Categories.Count; i++) {
Dictionary<string,object> category = new Dictionary<string, object>();
category.Add(prefix + "name", item.Categories[i].Name);
category.Add(prefix + "label", item.Categories[i].Label);
category.Add(prefix + "scheme", item.Categories[i].Scheme);
category = category.Union(util.ImportAttributeExtensions(item.Categories[i].AttributeExtensions, namespaces, xnsm)).ToDictionary(x => x.Key, x => x.Value);
category = category.Union(util.ImportElementExtensions(item.Categories[i].ElementExtensions, namespaces)).ToDictionary(x => x.Key, x => x.Value);
categories[i] = category;
}
}
if ((item.Contributors != null) && (item.Contributors.Count > 0)) {
object[] contributors = new object[item.Contributors.Count];
feature.Properties.Add(prefix + "categories", contributors);
for (int i = 0; i < item.Contributors.Count; i++) {
Dictionary<string,object> contributor = new Dictionary<string, object>();
contributor.Add(prefix + "name", item.Contributors[i].Name);
contributor.Add(prefix + "email", item.Contributors[i].Email);
contributor.Add(prefix + "uri", item.Contributors[i].Uri);
contributor = contributor.Union(util.ImportAttributeExtensions(item.Contributors[i].AttributeExtensions, namespaces, xnsm)).ToDictionary(x => x.Key, x => x.Value);
contributor = contributor.Union(util.ImportElementExtensions(item.Contributors[i].ElementExtensions, namespaces)).ToDictionary(x => x.Key, x => x.Value);
contributors[i] = contributor;
}
}
if (item.Copyright != null) {
feature.Properties.Add(prefix + "rights", item.Copyright.Text);
}
if (item.Summary != null) {
feature.Properties.Add(prefix + "summary", item.Summary.Text);
}
if (item.Content != null) {
feature.Properties.Add(prefix + "content", item.Summary.Text);
}
feature.Id = item.Id;
if (item.LastUpdatedTime != null)
feature.Properties.Add(prefix + "published", item.LastUpdatedTime);
if ((item.Links != null) && (item.Links.Count > 0)) {
feature.Links = item.Links;
}
if (item.Title != null)
feature.Properties.Add(prefix + "title", item.Title);
return feature;
}
return null;
}