XmlDocument creates an xmlns = "" solution when it is an innovative object.

Source: Internet
Author: User

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 ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.