XmlDocument 创新对象时, 产生 xmlns="" 的解决方案
今天做开发时碰到的XmlDocument 创新对象时, 产生 xmlns="" 的,经过分析总结了问题所在,有需要朋友参考一下,可能能帮助你解决这个问题。
1. 读取时,应该添加NameSpace.
代码如下 | 复制代码 |
var exclDef = excl.SelectSingleNode(@"ns:worksheet/ns:sheetData", excl.GetNameSpaceManager("ns")); public static XmlNamespaceManager GetNameSpaceManager(this XmlDocument xml, string NameSpace) { XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable); nsmgr.AddNamespace(NameSpace, xml.DocumentElement.NamespaceURI); return nsmgr; } |
2. 如果创建 节点,没有指明 NamespaceURI , 则会生成 xmlns="" , 其原因,参考:
/post_read.asp?BlogID=2524806&PostID=21711977
如果 ABC 三级的 NameSpaceURI 分别是 XYY , 那么, 生成的 ABC 的 NameSpaceURI分别是 AB空, C 不会生成 NameSpaceURI , 因为, C和其父项具有相同的 NameSpaceURI .
所以在创建 节点时, 为了不出现 NameSpaceURI , 请保持和节点父项相同的 NameSpaceURI .
var si = e.OwnerDocument.CreateElement("si", e.NamespaceURI); e.AppendChild(si);
另外, 创新 属性时, 不要指定 NameSpaceURI , 即 生成的 Xml 就没有特定的 NameSpaceURI .
var r = excl.CreateAttribute("r");

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

Common challenges faced by machine learning algorithms in C++ include memory management, multi-threading, performance optimization, and maintainability. Solutions include using smart pointers, modern threading libraries, SIMD instructions and third-party libraries, as well as following coding style guidelines and using automation tools. Practical cases show how to use the Eigen library to implement linear regression algorithms, effectively manage memory and use high-performance matrix operations.

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

Here's how to convert a MySQL query result array into an object: Create an empty object array. Loop through the resulting array and create a new object for each row. Use a foreach loop to assign the key-value pairs of each row to the corresponding properties of the new object. Adds a new object to the object array. Close the database connection.

Common causes and solutions for PHP Chinese garbled characters. With the development of the Internet, Chinese websites play an increasingly important role in our lives. However, in PHP development, the problem of Chinese garbled characters is still a common problem that troubles developers. This article will introduce the common causes of Chinese garbled characters in PHP and provide solutions. It also attaches specific code examples for readers' reference. 1. Common reasons: Inconsistent character encoding: Inconsistencies in PHP file encoding, database encoding, HTML page encoding, etc. may lead to Chinese garbled characters. database

As a fast and efficient programming language, Go language is widely popular in the field of back-end development. However, few people associate Go language with front-end development. In fact, using Go language for front-end development can not only improve efficiency, but also bring new horizons to developers. This article will explore the possibility of using the Go language for front-end development and provide specific code examples to help readers better understand this area. In traditional front-end development, JavaScript, HTML, and CSS are often used to build user interfaces

The Black Shark mobile phone is a gaming phone popular among young people. Its excellent performance and unique design have attracted the favor of many players. However, in daily use, some users reported that Black Shark phones automatically shut down when charging or failed to start after being connected to a charger, which caused trouble to users. This article will discuss the problem of automatic shutdown and startup of Black Shark mobile phones from the aspects of cause analysis and solutions to help users better solve this problem. 1. Cause Analysis Charger Quality Issues: Low-quality chargers may cause voltage instability, or
