本文整理汇总了C#中System.Xml.XmlNamespaceManager类的典型用法代码示例。如果您正苦于以下问题:C# XmlNamespaceManager类的具体用法?C# XmlNamespaceManager怎么用?C# XmlNamespaceManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlNamespaceManager类属于System.Xml命名空间,在下文中一共展示了XmlNamespaceManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: XmlParserContext
/// <include file='doc\XmlParserContext.uex' path='docs/doc[@for="XmlParserContext.XmlParserContext3"]/*' />
public XmlParserContext(XmlNameTable nt, XmlNamespaceManager nsMgr, String docTypeName,
String pubId, String sysId, String internalSubset, String baseURI,
String xmlLang, XmlSpace xmlSpace, Encoding enc)
{
if (nsMgr != null) {
if (nt == null) {
_nt = nsMgr.NameTable;
}
else {
if ( (object)nt != (object) nsMgr.NameTable ) {
throw new XmlException(Res.Xml_NotSameNametable);
}
_nt = nt;
}
}
else {
_nt = nt;
}
_nsMgr = nsMgr;
_docTypeName = (null == docTypeName ? String.Empty : docTypeName);
_pubId = (null == pubId ? String.Empty : pubId);
_sysId = (null == sysId ? String.Empty : sysId);
_internalSubset = (null == internalSubset ? String.Empty : internalSubset);
_baseURI = (null == baseURI ? String.Empty : baseURI);
_xmlLang = (null == xmlLang ? String.Empty : xmlLang);
_xmlSpace = xmlSpace;
_encoding = enc;
}
示例2: from
public void from(XmlNode node, XmlNamespaceManager xnm, string prefix, string subfix)
{
Type type = this.GetType();
FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
foreach (FieldInfo field in fields)
{
string query = prefix +ObjectUtil.GetSimpleName(field) + subfix;
try
{
string value = null;
XmlNode tempNode;
if (xnm != null)
{
tempNode = node.SelectSingleNode(query, xnm);
}
else
{
tempNode = node.SelectSingleNode(query);
}
if (tempNode == null) {
field.SetValue(this,XML_NULL);
continue;
}
value = tempNode.InnerText;
field.SetValue(this, value);
}
catch (Exception ex) { }
}
}
示例3: Evaluate
/// <summary>
/// Evaluates the given expression and returns the typed result.
/// </summary>
public static object Evaluate(string expression, XPathNavigator source,
XmlNamespaceManager context)
{
XPathExpression expr = GetCompiledExpression(expression, source);
expr.SetContext(context);
return source.Evaluate(expr);
}
示例4: TelemetryInitializerInstall
protected void TelemetryInitializerInstall(string sourceDocument, params string[] telemetryInitializerTypes)
{
string resourceName = "Microsoft.ApplicationInsights.Resources.ApplicationInsights.config.install.xdt";
Stream stream = typeof(ModuleTransformTests).Assembly.GetManifestResourceStream(resourceName);
using (StreamReader reader = new StreamReader(stream))
{
string transform = reader.ReadToEnd();
XmlTransformation transformation = new XmlTransformation(transform, false, null);
XmlDocument targetDocument = new XmlDocument();
targetDocument.LoadXml(sourceDocument);
transformation.Apply(targetDocument);
XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable());
manager.AddNamespace("ai", AppInsightsNamespace);
int moduleIndex = 0;
foreach (XPathNavigator module in targetDocument.CreateNavigator().Select("/ai:ApplicationInsights/ai:TelemetryInitializers/ai:Add/@Type", manager))
{
string contextInitializerType = telemetryInitializerTypes[moduleIndex++];
Assert.Equal(module.Value, contextInitializerType);
}
Assert.Equal(moduleIndex, telemetryInitializerTypes.Length);
}
}
开发者ID:Microsoft,项目名称:ApplicationInsights-dotnet-server,代码行数:25,代码来源:TelemetryInitializerTransformTests.cs
示例5: ModifyPrintTicket
public static PrintTicket ModifyPrintTicket(PrintTicket ticket, string featureName, string newValue)
{
if (ticket == null)
{
throw new ArgumentNullException("ticket");
}
var xmlDoc = new XmlDocument();
xmlDoc.Load(ticket.GetXmlStream());
var manager = new XmlNamespaceManager(xmlDoc.NameTable);
manager.AddNamespace(xmlDoc.DocumentElement.Prefix, xmlDoc.DocumentElement.NamespaceURI);
var xpath = string.Format("//psf:Feature[contains(@name, 'InputBin')]/psf:Option", featureName);
var node = xmlDoc.SelectSingleNode(xpath, manager);
if (node != null)
{
node.Attributes["name"].Value = newValue;
}
var printTicketStream = new MemoryStream();
xmlDoc.Save(printTicketStream);
printTicketStream.Position = 0;
var modifiedPrintTicket = new PrintTicket(printTicketStream);
return modifiedPrintTicket;
}
示例6: Main
static void Main( string[] args )
{
if ( args.Length != 1 )
{
return;
}
string fileName = args[ 0 ];
StringBuilder fileContent = new StringBuilder( System.IO.File.ReadAllText( fileName ) );
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml( fileContent.ToString() );
System.Xml.XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager( xdoc.NameTable );
xmlnsManager.AddNamespace( "gpx", "http://www.topografix.com/GPX/1/0" );
XmlNodeList timeNodes = xdoc.SelectNodes( "//gpx:time", xmlnsManager );
foreach ( XmlNode timeNode in timeNodes )
{
string[] split1 = timeNode.InnerText.Split( 'T' );
string[] splitDays = split1[ 0 ].Split( '-' );
string[] splitHours = split1[ 1 ].Replace( "Z", "" ).Split( ':' );
fileContent.Replace( timeNode.InnerText, new DateTime( int.Parse( splitDays[ 0 ] ), int.Parse( splitDays[ 1 ] ), int.Parse( splitDays[ 2 ] ),
int.Parse( splitHours[ 0 ] ), int.Parse( splitHours[ 1 ] ), int.Parse( splitHours[ 2 ] ) ).ToUniversalTime().ToString( "s" ) + "Z" );
}
System.IO.File.WriteAllText( fileName.Replace( ".gpx", "-fix.gpx" ), fileContent.ToString() );
}
示例7: CancelAppointment
public bool CancelAppointment(HackExchangeContext context, CalendarItem appointment)
{
var url = context.Endpoint;
var request = new HttpRequestMessage(HttpMethod.Post, url);
var postBodyTemplate = LoadXml("CancelAppointment");
var postBody = string.Format(postBodyTemplate, appointment.Id, appointment.ChangeKey);
request.Content = new StringContent(postBody, Encoding.UTF8, "text/xml");
var clientHandler = new HttpClientHandler()
{
Credentials = context.Credentials
};
using (var client = new HttpClient(clientHandler))
{
var response = client.SendAsync(request).Result;
var responseBody = response.Content.ReadAsStringAsync().Result;
var doc = new XPathDocument(new StringReader(responseBody));
var nav = doc.CreateNavigator();
var nsManager = new XmlNamespaceManager(nav.NameTable);
nsManager.AddNamespace("m", "http://schemas.microsoft.com/exchange/services/2006/messages");
nsManager.AddNamespace("t", "http://schemas.microsoft.com/exchange/services/2006/types");
var responseClass = EvaluateXPath(nav, nsManager, "//m:DeleteItemResponseMessage/@ResponseClass");
return responseClass == "Success";
}
}
示例8: Feed
public Feed(IXPathNavigable navigable)
{
navigator = navigable.CreateNavigator();
manager = new XmlNamespaceManager(navigator.NameTable);
manager.AddNamespace("f", "http://hl7.org/fhir");
manager.AddNamespace("atom", "http://www.w3.org/2005/Atom");
}
示例9: 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;
}
示例10: XmlException
SelectRequiredSingleNode
(
XmlNode node,
String xPath,
XmlNamespaceManager xmlNamespaceManager
)
{
Debug.Assert(node != null);
Debug.Assert( !String.IsNullOrEmpty(xPath) );
XmlNode oSelectedNode;
if ( !TrySelectSingleNode(node, xPath, xmlNamespaceManager,
out oSelectedNode) )
{
throw new XmlException( String.Format(
"An XML node with the name \"{0}\" is missing a required"
+ " descendent node. The XPath is \"{1}\"."
,
node.Name,
xPath
) );
}
return (oSelectedNode);
}
示例11: Initialize
public void Initialize(XmlDocument basedata, XmlNamespaceManager namespaces, RDFTriple rdftriple)
{
BaseData = basedata;
Namespaces = namespaces;
RDFTriple = rdftriple;
UploadInfoToORCID1.Initialize(basedata, namespaces, rdftriple);
}
示例12: QueryAndNamespace
public void QueryAndNamespace()
{
try
{
var output = "";
var path = Server.MapPath("~/App_Data/bookstore.xml");
XPathDocument document = new XPathDocument(path);
XPathNavigator navigator = document.CreateNavigator();
XPathExpression query = navigator.Compile("/bookstore:bookstore/bookstore:book");
XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);
manager.AddNamespace("bookstore", "urn:newbooks-schema");
query.SetContext(manager);
XPathNodeIterator nodes = navigator.Select(query);
while (nodes.MoveNext())
{
output += nodes.Current.OuterXml;
}
Textarea4.InnerHtml = output;
}
catch (Exception ex)
{
Textarea4.InnerHtml = ex.Message;
}
}
示例13: PatchSystemFolder_Add
private static void PatchSystemFolder_Add(string typeName, params string[] additionalContentTypeNames)
{
var ct = ContentType.GetByName(typeName);
var xml = new XmlDocument();
var nsmgr = new XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("x", ContentType.ContentDefinitionXmlNamespace);
xml.Load(ct.Binary.GetStream());
var list = new List<string>();
var element = (XmlElement)xml.DocumentElement.SelectSingleNode("x:AllowedChildTypes", nsmgr);
if (element == null)
{
var fieldsElement = (XmlElement)xml.DocumentElement.SelectSingleNode("x:Fields", nsmgr);
//if (fieldsElement == null)
//{
//}
element = xml.CreateElement("", "AllowedChildTypes", ContentType.ContentDefinitionXmlNamespace);
xml.DocumentElement.InsertBefore(element, fieldsElement);
}
else
{
list.AddRange(element.InnerXml.Split(" \t\r\n,;".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries).Select(x=>x.Trim()));
}
if (additionalContentTypeNames != null && additionalContentTypeNames.Length > 0)
list.AddRange(additionalContentTypeNames);
element.InnerText = string.Join(" ", list);
ContentTypeInstaller.InstallContentType(xml.OuterXml);
}
示例14: ResinConf
public ResinConf(String file)
{
_xPathDoc = new XPathDocument(file);
_docNavigator = _xPathDoc.CreateNavigator();
_xmlnsMgr = new XmlNamespaceManager(_docNavigator.NameTable);
_xmlnsMgr.AddNamespace("caucho", "http://caucho.com/ns/resin");
}
示例15: Execute
public override bool Execute()
{
try {
var document = new XmlDocument();
document.Load(this.XmlFileName);
var navigator = document.CreateNavigator();
var nsResolver = new XmlNamespaceManager(navigator.NameTable);
if (!string.IsNullOrEmpty(this.Prefix) && !string.IsNullOrEmpty(this.Namespace)) {
nsResolver.AddNamespace(this.Prefix, this.Namespace);
}
var expr = XPathExpression.Compile(this.XPath, nsResolver);
var iterator = navigator.Select(expr);
while (iterator.MoveNext()) {
iterator.Current.DeleteSelf();
}
using (var writer = new XmlTextWriter(this.XmlFileName, Encoding.UTF8)) {
writer.Formatting = Formatting.Indented;
document.Save(writer);
writer.Close();
}
}
catch (Exception exception) {
base.Log.LogErrorFromException(exception);
return false;
}
base.Log.LogMessage("Updated file '{0}'", new object[] { this.XmlFileName });
return true;
}