Xmlns = \ "\" is generated when the XmlDocument innovation object encountered during development today. The problem is analyzed and summarized. If you need a friend to refer to it, it may help you solve this problem.
1. Add NameSpace when reading.
| The Code is as follows: |
Copy code |
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. If NamespaceURI is not specified when a node is created, xmlns = "" is generated. For the reason, refer:
/Post_read.asp? BlogID = 2524806 & PostID = 21711977
If the third-level NameSpaceURI of ABC is XYY, the generated ABC NameSpaceURI is AB null, and C does not generate NameSpaceURI, because C and its parent have the same NameSpaceURI.
Therefore, when creating a node, ensure that the NameSpaceURI is the same as the parent item of the node.
Var si = e. OwnerDocument. CreateElement ("si", e. NamespaceURI); e. AppendChild (si );
In addition, do not specify NameSpaceURI when creating attributes. That is, the generated Xml does not have a specific NameSpaceURI.
Var r = excl. CreateAttribute ("r ");