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
Copy file name to clipboardExpand all lines: docs/standard/linq/create-document-namespaces-csharp.md
+14-5Lines changed: 14 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: How to create a document with namespaces in C# - LINQ to XML
3
3
description: Use the XNamespace object in C# to create documents that have default namespaces or namespaces with a prefix.
4
-
ms.date: 07/20/2015
4
+
ms.date: 01/23/2025
5
5
ms.topic: how-to
6
6
---
7
7
@@ -60,6 +60,8 @@ The following example shows the creation of a document that contains two namespa
60
60
61
61
By including namespace attributes in the root element, the namespaces are serialized so that `http://www.adventure-works.com` is the default namespace, and `www.fourthcoffee.com` is serialized with a prefix of `fc`. To create an attribute that declares a default namespace, you create an attribute with the name `xmlns`, without a namespace. The value of the attribute is the default namespace URI.
62
62
63
+
If a default namespace declaration is in scope, it applies to child `XElement` objects by prefixing their local names with the corresponding `XNamespace` object. On the other hand, default namespace declarations do not apply directly to attribute names. So, `XAttribute` objects in the default namespace are defined by *not* prefixing their local name with the corresponding `XNamespace` object.
64
+
63
65
```csharp
64
66
// The http://www.adventure-works.com namespace is forced to be the default namespace.
0 commit comments