本文整理汇总了C#中System.Xml.XmlNamespaceManager.LookupNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNamespaceManager.LookupNamespace方法的具体用法?C# XmlNamespaceManager.LookupNamespace怎么用?C# XmlNamespaceManager.LookupNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlNamespaceManager
的用法示例。
在下文中一共展示了XmlNamespaceManager.LookupNamespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMasterContents
// Public Methods
#region CreateMasterContents(string styleFilePath, ArrayList odtFiles)
public void CreateMasterContents(string styleFilePath, ArrayList odtFiles)
{
var doc = new XmlDocument();
doc.Load(styleFilePath);
var nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
nsmgr.AddNamespace("text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
nsmgr.AddNamespace("xlink", "http://www.w3.org/1999/xlink");
// if new stylename exists
XmlElement root = doc.DocumentElement;
string style = "//office:text";
if (root != null)
{
XmlNode node = root.SelectSingleNode(style, nsmgr); // work
if (node != null)
{
for (int i = 0; i < odtFiles.Count; i++) // ODM - ODT
{
string outputFile = odtFiles[i].ToString();
outputFile = Path.ChangeExtension(outputFile, "odt");
XmlNode newNode;
newNode = doc.CreateNode("element", "text:section", nsmgr.LookupNamespace("text"));
//attribute
XmlAttribute xmlAttrib = doc.CreateAttribute("text:style-name", nsmgr.LookupNamespace("text"));
xmlAttrib.Value = "SectODM";
newNode.Attributes.Append(xmlAttrib);
xmlAttrib = doc.CreateAttribute("text:name", nsmgr.LookupNamespace("text"));
xmlAttrib.Value = outputFile;
newNode.Attributes.Append(xmlAttrib);
xmlAttrib = doc.CreateAttribute("text:protected", nsmgr.LookupNamespace("text"));
xmlAttrib.Value = "false";
newNode.Attributes.Append(xmlAttrib);
XmlNode newNode1 = doc.CreateNode("element", "text:section-source", nsmgr.LookupNamespace("text"));
//attribute
XmlAttribute xmlAttrib1 = doc.CreateAttribute("xlink:href", nsmgr.LookupNamespace("xlink"));
xmlAttrib1.Value = "../" + outputFile;
newNode1.Attributes.Append(xmlAttrib1);
xmlAttrib1 = doc.CreateAttribute("text:filter-name", nsmgr.LookupNamespace("text"));
xmlAttrib1.Value = "writer8";
newNode1.Attributes.Append(xmlAttrib1);
newNode.AppendChild(newNode1);
node.AppendChild(newNode);
}
}
}
doc.Save(styleFilePath);
}
示例2: Insert
/// <summary>
/// Inserts Xml markup representing format attributes inside a specific paragraph or paragraph run
/// </summary>
/// <param name="document">Document to insert formatting Xml tags</param>
/// <param name="xpathInsertionPoint">Paragraph or paragraph run to set format</param>
/// <param name="content">Formatting tags</param>
public static OpenXmlPowerToolsDocument Insert(WmlDocument doc, string xpathInsertionPoint, string content)
{
using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
{
using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
{
XDocument xDocument = document.MainDocumentPart.GetXDocument();
XmlDocument xmlMainDocument = new XmlDocument();
xmlMainDocument.Load(xDocument.CreateReader());
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
namespaceManager.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
XmlNodeList insertionPoints = xmlMainDocument.SelectNodes(xpathInsertionPoint, namespaceManager);
if (insertionPoints.Count == 0)
throw new ArgumentException("The xpath query did not return a valid location.");
foreach (XmlNode insertionPoint in insertionPoints)
{
XmlNode propertiesElement = insertionPoint.SelectSingleNode(@"w:pPr|w:rPr", namespaceManager);
if (insertionPoint.Name == "w:p")
{
// Checks if the rPr or pPr element exists
if (propertiesElement == null)
{
propertiesElement = xmlMainDocument.CreateElement("w", "pPr", namespaceManager.LookupNamespace("w"));
insertionPoint.PrependChild(propertiesElement);
}
}
else if (insertionPoint.Name == "w:r")
{
// Checks if the rPr or pPr element exists
if (propertiesElement == null)
{
propertiesElement = xmlMainDocument.CreateElement("w", "rPr", namespaceManager.LookupNamespace("w"));
insertionPoint.PrependChild(propertiesElement);
}
}
if (propertiesElement != null)
{
propertiesElement.InnerXml += content;
}
else
{
throw new ArgumentException("Specified xpath query result is not a valid location to place a formatting markup");
}
}
XDocument xNewDocument = new XDocument();
using (XmlWriter xWriter = xNewDocument.CreateWriter())
xmlMainDocument.WriteTo(xWriter);
document.MainDocumentPart.PutXDocument(xNewDocument);
}
return streamDoc.GetModifiedDocument();
}
}
示例3: ParseXPathString
private static string ParseXPathString(XPathLexer lexer, XmlNamespaceManager namespaceManager, bool throwOnFailure)
{
int firstTokenChar = lexer.FirstTokenChar;
if (lexer.MoveNext())
{
XPathToken token = lexer.Token;
StringBuilder builder = new StringBuilder(ParseXPathString(lexer, namespaceManager, throwOnFailure));
if (XPathTokenID.NameTest == token.TokenID)
{
string prefix = token.Prefix;
if (!string.IsNullOrEmpty(prefix))
{
string str3 = namespaceManager.LookupNamespace(prefix);
if (!string.IsNullOrEmpty(str3))
{
builder = builder.Replace(prefix, str3, firstTokenChar, prefix.Length);
}
else if (throwOnFailure)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new IndexOutOfRangeException(System.ServiceModel.SR.GetString("ConfigXPathNamespacePrefixNotFound", new object[] { prefix })));
}
}
}
return builder.ToString();
}
return lexer.ConsumedSubstring();
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:XPathMessageFilterElementComparer.cs
示例4: _GetNewContact
private static Stream _GetNewContact()
{
// The emptycontact.xml provides a basic template for a new contact.
// Need to replace template data in it with unique data, e.g. ContactID/Value and CreationDate,
// before trying to load it as a contact.
// Could keep reusing the same XmlDocument, but would need to guard it for multiple-thread access.
var xmlDoc = new XmlDocument();
_EmptyContactStream.Position = 0;
xmlDoc.Load(_EmptyContactStream);
var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsmgr.AddNamespace("c", SchemaStrings.ContactNamespace);
Assert.AreEqual(SchemaStrings.ContactNamespace, nsmgr.LookupNamespace("c"));
var contactIdElement = xmlDoc.SelectSingleNode("./c:contact/c:ContactIDCollection/c:ContactID", nsmgr) as XmlElement;
contactIdElement.SetAttribute(SchemaStrings.ElementId, SchemaStrings.ContactNamespace, Guid.NewGuid().ToString());
var valueElement = contactIdElement.FirstChild as XmlElement;
valueElement.InnerText = Guid.NewGuid().ToString();
var creationDateElement = xmlDoc.SelectSingleNode("./c:contact/c:CreationDate", nsmgr) as XmlElement;
creationDateElement.InnerText = XmlUtil.DateTimeNowString;
Stream stm = new MemoryStream();
xmlDoc.Save(stm);
return stm;
}
示例5: Main
/// <summary>
/// This function will set all content files to be embedded resources
/// </summary>
/// <param name="args">
///Command Line Arguments:
/// 0 - Path to project file.
/// </param>
static void Main(string[] args)
{
string pathToProject = args[0];
if (System.IO.File.Exists(pathToProject))
{
XmlDocument projectFile = new XmlDocument();
projectFile.Load(pathToProject);
XmlNamespaceManager nsMgr = new XmlNamespaceManager(projectFile.NameTable);
nsMgr.AddNamespace("build", "http://schemas.microsoft.com/developer/msbuild/2003");
XmlNodeList contentNodes = projectFile.SelectNodes("build:Project/build:ItemGroup/build:Content", nsMgr);
bool wasProjectModified = false;
foreach (XmlNode contentNode in contentNodes)
{
if (contentNode.Attributes["Include"] != null)
{
string extension = System.IO.Path.GetExtension(contentNode.Attributes["Include"].Value);
if (!excludedExtensions.Contains(extension))
{
XmlNode resourceNode = projectFile.CreateElement("EmbeddedResource", nsMgr.LookupNamespace("build"));
XmlAttribute includeAttribute = projectFile.CreateAttribute("Include");
includeAttribute.Value = contentNode.Attributes["Include"].Value;
resourceNode.Attributes.Append(includeAttribute);
XmlNode parentNode = contentNode.ParentNode;
parentNode.ReplaceChild(resourceNode, contentNode);
wasProjectModified = true;
}
}
}
if (wasProjectModified)
{
projectFile.Save(pathToProject);
}
}
}
示例6: AddFile
public void AddFile(byte[] data, string path)
{
XmlDocument manifest = GetXMLDocument ("META-INF/manifest.xml");
XmlNamespaceManager nsManager = new XmlNamespaceManager (manifest.NameTable);
nsManager.AddNamespace ("manifest", "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0");
XmlNode manifestNode = manifest.SelectSingleNode("/manifest:manifest",nsManager);
XmlElement fileEntry = manifest.CreateElement ("manifest", "file-entry", nsManager.LookupNamespace("manifest"));
fileEntry.SetAttribute ("full-path", nsManager.LookupNamespace ("manifest"),path);
fileEntry.SetAttribute ("media-type", nsManager.LookupNamespace ("manifest"), "image/png");
manifestNode.AppendChild(fileEntry);
using (var fileStream = new MemoryStream (data)) {
odtZip.BeginUpdate ();
StreamStaticDataSource sds = new StreamStaticDataSource ();
sds.SetStream (fileStream);
odtZip.Add (sds, path);
odtZip.CommitUpdate ();
}
UpdateXmlDocument (manifest, "META-INF/manifest.xml");
}
示例7: Description
public Description(XmlNode elm, XmlNamespaceManager nsmgr)
{
string asmv2 = nsmgr.LookupNamespace("asmv2");
if (elm.Attributes["publisher", asmv2] != null)
Publisher = elm.Attributes["publisher", asmv2].Value;
if (elm.Attributes["product", asmv2] != null)
Product = elm.Attributes["product", asmv2].Value;
if (elm.Attributes["supportUrl", asmv2] != null)
SupportUrl = new Uri(elm.Attributes["supportUrl", asmv2].Value);
}
示例8: CreateElement
public static XmlElement CreateElement(XmlElement parent, string name, string innerText, XmlNamespaceManager nsMgr)
{
if (parent == null)
{
throw new Exception("Passed in a null node, which should never happen. Tell Gus!");
}
XmlElement newChild = parent.OwnerDocument.CreateElement(name, nsMgr.LookupNamespace("ns1"));
XmlElement element2 = (XmlElement) parent.AppendChild(newChild);
element2.InnerText = innerText;
return (XmlElement) parent.AppendChild(element2);
}
示例9: GetAttributeValue
/// <summary>
/// Gets a named attribute value of an xml element
/// </summary>
/// <param name="xml">The xml node</param>
/// <param name="attribute">The attribute name. It could be of prefix:localname form</param>
/// <param name="nsResolver">The Xml namespace resolver object</param>
/// <returns>The value of named attribute if found; null otherwise</returns>
public static string GetAttributeValue(this XElement xml, string attribute, XmlNamespaceManager nsResolver)
{
string fullName = attribute;
string[] name = attribute.Split(new char[]{':'}, 2);
if (name != null && name.Length == 2)
{
var ns = nsResolver.LookupNamespace(name[0]);
fullName = string.Format("{{{0}}}{1}", ns, name[1]);
}
return GetAttributeValue(xml, fullName);
}
示例10: Xml2Xsd
public Xml2Xsd(System.Xml.XmlNameTable tableName)
{
// initialize code here
nsmgr = new XmlNamespaceManager(tableName);
nsmgr.AddNamespace("xsd", schemaNS);
nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
nsmgr.AddNamespace("msdata", "urn:schemas-microsoft-com:xml-msdata");
foreach (String prefix in nsmgr)
{
XmlNS.Add(prefix, nsmgr.LookupNamespace(prefix));
}
}
示例11: GetOrCreateElement
public static XmlNode GetOrCreateElement(XmlNode node, string xpathNotIncludingElement,
string elementName, string nameSpace, XmlNamespaceManager nameSpaceManager, IComparer<XmlNode> nodeOrderComparer)
{
//enhance: if the parent path isn't found, strip of the last piece and recurse,
//so that the path will always be created if needed.
XmlNode parentNode = node.SelectSingleNode(xpathNotIncludingElement,nameSpaceManager);
if (parentNode == null)
{
throw new ApplicationException(string.Format("The path {0} could not be found", xpathNotIncludingElement));
}
string prefix = "";
if (!String.IsNullOrEmpty(nameSpace))
{
prefix = nameSpace + ":";
}
XmlNode n = parentNode.SelectSingleNode(prefix+elementName,nameSpaceManager);
if (n == null)
{
if (!String.IsNullOrEmpty(nameSpace))
{
n = GetDocument(node).CreateElement(nameSpace, elementName, nameSpaceManager.LookupNamespace(nameSpace));
}
else
{
n = GetDocument(node).CreateElement(elementName);
}
if (nodeOrderComparer == null)
{
parentNode.AppendChild(n);
}
else
{
XmlNode insertAfterNode = null;
foreach (XmlNode childNode in parentNode.ChildNodes)
{
if (childNode.NodeType != XmlNodeType.Element)
{
continue;
}
if (nodeOrderComparer.Compare(n, childNode) < 0)
{
break;
}
insertAfterNode = childNode;
}
parentNode.InsertAfter(n, insertAfterNode);
}
}
return n;
}
示例12: SetTextInElement
public static XmlNode SetTextInElement(XmlElement element, string name, string text, XmlNamespaceManager nsMgr)
{
if (element == null)
{
throw new Exception("Passed in a null node, which should never happen.");
}
XmlElement newChild = (XmlElement) element.SelectSingleNode("descendant::ns1:" + name, nsMgr);
if (newChild == null)
{
newChild = (XmlElement) element.AppendChild(element.OwnerDocument.CreateElement(name, nsMgr.LookupNamespace("ns1")));
}
newChild.InnerText = text;
return element.AppendChild(newChild);
}
示例13: NamespaceQualifiedValue
internal NamespaceQualifiedValue(XmlNamespaceManager NamespaceManager, string FullyQualifiedValue)
{
thisFullyQualifiedValue = FullyQualifiedValue;
thisFullyQualifiedValueComponents = thisFullyQualifiedValue.Split(':');
if (thisFullyQualifiedValueComponents.Length == 1)
{
thisLocalName = thisFullyQualifiedValueComponents[0];
thisNamespace = string.Empty;
thisNamespaceUri = string.Empty;
}
else
{
thisLocalName = thisFullyQualifiedValueComponents[1];
thisNamespace = thisFullyQualifiedValueComponents[0];
thisNamespaceUri = NamespaceManager.LookupNamespace(thisNamespace);
}
}
示例14: DynamicContext
/// <summary>
/// Initializes a new instance of the <see cref="DynamicContext"/> class.
/// </summary>
/// <param name="context">A previously filled context with the namespaces to use.</param>
/// <param name="table">The NameTable to use.</param>
public DynamicContext(XmlNamespaceManager context, NameTable table) : base(table)
{
object xml = table.Add(XmlNamespaces.Xml);
object xmlns = table.Add(XmlNamespaces.XmlNs);
if (context != null)
{
foreach (string prefix in context)
{
string uri = context.LookupNamespace(prefix);
// Use fast object reference comparison to omit forbidden namespace declarations.
if (Object.Equals(uri, xml) || Object.Equals(uri, xmlns))
continue;
base.AddNamespace(prefix, uri);
}
}
}
示例15: InitNamespaceManager
private void InitNamespaceManager(bool isHtmlDocument)
{
this.XmlNamespaceManager = new XmlNamespaceManager(XPathNavigator.NameTable);
if (isHtmlDocument)
{
string ns = XmlNamespaceManager.LookupNamespace("xmlns");
if (!string.IsNullOrEmpty(ns))
{
}
}
else
{
XPathNodeIterator iterator = XPathNavigator.Select("//namespace::*[not(. = ../../namespace::*)]");
while (iterator.MoveNext())
{
XmlNamespaceManager.AddNamespace(iterator.Current.Name, iterator.Current.Value);
}
}
}