Home > other >  New XML node properties, how to prevent automatic increase namespace???????
New XML node properties, how to prevent automatic increase namespace???????

Time:11-16

1. With a namespace XML below
<? The XML version="1.0" encoding="utf-8"?>
0


2. Add a node and the properties, the following is a part of the code:
Xmldoc. Load (reader);
Reader. The Close ();
NamespaceManager=new XmlNamespaceManager (xmldoc NameTable);//a namespace of the XML file to this a few words!
NamespaceManager. AddNamespace (" A ", "http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition");//the default namespaces also went to add
NamespaceManager. AddNamespace (" rd ", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
RootXE=xmldoc. DocumentElement;//DocumentElement access to the root of the XML document object XmlElement.

Private void invoke the (string nodename, string location, string value)
{
XmlNode ItemND=rootXE. SelectSingleNode ("/A Report/A: ReportSections/A: ReportSection/A: Body/A: ReportItems ", namespaceManager);//selectSingleNode, according to an XPath expression to get qualified first node.
The switch (nodename. Substring (0, 2))//txbJP01, JP01, Rectangle1, Line4
{
Case "tx" :
break;
Case "JP" :
break;
Case "Re" :
break;
A case of "Li" :
XmlElement xeLine=xmldoc. The CreateElement method (" Line ");//create the Line node
XmlAttribute xmlAttuName=xmldoc. CreateAttribute (" Name ");//create a properties
XmlAttuName. The InnerText=nodename;//attribute values, Line10 start
XeLine. SetAttributeNode (xmlAttuName);
3. After the program is running, in the Name attribute automatically add the XMLNS="", how to make the program does not increase the namespace?
</style>

120.000 cm
16.75458 cm
0 cm & lt;/Height>
2.70933 cm
21 & lt;/Zindex>
<style>

<style> Solid</style>

</style>


11.69 in
<style/& gt;

8.27 in

CodePudding user response:

To find the answer! After you met can reference!

//1) : when we are in the AppendChild, if ParentNode is with XMLNS attribute, and you've added node is not specified when creating XMLNS or specified as empty, child nodes will appear XMLNS="" attribute, eventually can't take out,
//2) : when the parent node has the XMLNS attribute, child node must specify the XMLNS attribute, but when the XMLNS attribute and parent node namespace phase at the same time, the child node does not display the XMLNS attribute,

For example: the XmlElement xeLine=xmldoc. CreateElement method (" Line ", this. Xmldoc. DocumentElement. NamespaceURI);//create the Line node
  • Related