You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use the <xref:System.Xml.XmlConvert.EncodeName%2A> method with the <xref:System.Xml.XmlWriter> class to ensure the names being written are valid XML names. The following C# code converts the name "Order Detail" into a valid XML name and writes the element `<Order_0x0020_Detail>My order</Order_0x0020_Detail>`.
`Note to Inheritors` If you overload this function, it cannot be used for extensibility. Instead, you can return an element created by the base class, in this case, `XmlDataDocument`. See the following example.
195
195
196
-
```
196
+
```csharp
197
197
class MyXmlDataDocument : XmlDataDocument {
198
198
public override XmlElement CreateElement(string prefix, string localName, string nsURI) {
199
199
//Ensure we are returning the base class implementation of element.
@@ -640,13 +640,13 @@ class MyXmlDataDocument : XmlDataDocument {
640
640
641
641
If the current node and its following siblings look similar to the following:
`Load` throws an exception, because a document cannot have two root-level elements. If the current node and its following siblings look similar to the following:
The binary format only supports one text node as the attribute value and therefore buffers the values written to it to emit a single node, as shown in the following sample code.
`InnerXml` removes redundant namespace declarations. As a result, numerous cut and paste operations do not increase the size of your document with redundant namespace declarations. Consider the following XSL document:
If you move `InnerXml` from a document with no default namespace to a document with a default namespace, the behavior is a little different. Consider the following XML string:
2436
2436
2437
-
```
2437
+
```xml
2438
2438
<test>
2439
2439
<item>123</item>
2440
2440
</test>
2441
2441
```
2442
2442
2443
2443
`InnerXml` returns a plain XML string with no namespace declarations:
2444
2444
2445
-
```
2445
+
```xml
2446
2446
<item>123</item>
2447
2447
```
2448
2448
2449
2449
If you then insert this string into a document that does have a default namespace, such as the following:
2450
2450
2451
-
```
2451
+
```xml
2452
2452
<test2 xmlns="urn:1">
2453
2453
</test>
2454
2454
```
2455
2455
2456
2456
`InnerXml` parses the string in context, and the new nodes pick up the urn:1 namespace. The result looks like this:
2457
2457
2458
-
```
2458
+
```xml
2459
2459
<test2 xmlns="urn:1">
2460
2460
<item>123</item>
2461
2461
</test>
2462
2462
```
2463
2463
2464
2464
Now when you ask for the `InnerXml` you get back the following:
2465
2465
2466
-
```
2466
+
```xml
2467
2467
<item xmlns="urn:1">123</item>
2468
2468
```
2469
2469
2470
2470
If you explicitly want the inserted item to preserve the fact that it came from a document that had no namespace then you need to manually add an xmlns= "" declaration and insert the resulting string:
`ReadNode` can also read attributes, but in this case it does not advance the reader to the next attribute. This allows you to write the following C# code:
3490
3490
3491
-
```
3491
+
```csharp
3492
3492
XmlDocument doc = new XmlDocument();
3493
3493
while (reader.MoveToNextAttribute())
3494
3494
{
@@ -3577,7 +3577,7 @@ while (reader.MoveToNextAttribute())
3577
3577
3578
3578
When the document is saved, xmlns attributes are generated to persist the node identity (local name + namespace URI) correctly. For example, the following C# code
When the document is saved, xmlns attributes are generated to persist the node identity (local name + namespace URI) correctly. For example, the following C# code
When the document is saved, xmlns attributes are generated to persist the node identity (LocalName + NamespaceURI) correctly. For example, the following C# code
The value of this property varies depending on the node type. Nodes which are children of external EntityReference nodes return the location of the entity itself. For example, consider the following XML document:
65
65
66
-
```
66
+
```xml
67
67
<!DOCTYPE item [
68
68
<!ENTITY xyz SYSTEM "a/b.xml">
69
69
]>
@@ -89,7 +89,7 @@
89
89
90
90
As a second example, given the following XML document:
91
91
92
-
```
92
+
```xml
93
93
<!DOCTYPE Mydata SYSTEM "http://localhost/doctype.dtd">
<TypeSignatureLanguage="C#"Value="public class XmlNamespaceManager : System.Collections.IEnumerable, System.Xml.IXmlNamespaceResolver" />
3
3
<TypeSignatureLanguage="ILAsm"Value=".class public auto ansi beforefieldinit XmlNamespaceManager extends System.Object implements class System.Collections.IEnumerable, class System.Xml.IXmlNamespaceResolver" />
The following code shows how to use the <xref:System.Collections.IEnumerator> to view all the namespace pairs stored in the <xref:System.Xml.XmlNamespaceManager> object.
0 commit comments