XNamespace.Addition(XNamespace, String) Operator
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Combines an XNamespace object with a local name to create an XName.
public:
static System::Xml::Linq::XName ^ operator +(System::Xml::Linq::XNamespace ^ ns, System::String ^ localName);
public static System.Xml.Linq.XName operator + (System.Xml.Linq.XNamespace ns, string localName);
static member ( + ) : System.Xml.Linq.XNamespace * string -> System.Xml.Linq.XName
Public Shared Operator + (ns As XNamespace, localName As String) As XName
Parameters
- ns
- XNamespace
An XNamespace that contains the namespace.
Returns
The new XName constructed from the namespace and local name.
Examples
The following example shows the use of the +
operator to create an XName from an XNamespace and a local name.
XNamespace aw = "http://www.adventure-works.com";
XElement root = new XElement(aw + "Root",
new XElement(aw + "Child")
);
Console.WriteLine(root);
Dim aw As XNamespace = "http://www.adventure-works.com"
Dim root As XElement = New XElement(aw + "Root", _
New XElement(aw + "Child") _
)
Console.WriteLine(root)
In Visual Basic, this is the preferred idiom:
Imports <xmlns="http://www.adventure-works.com">
Module Module1
Sub Main()
Dim aw As XNamespace = GetXmlNamespace()
Dim root As XElement = _
<Root>
<Child/>
</Root>
Console.WriteLine(root)
End Sub
End Module
This example produces the following output:
<Root xmlns="http://www.adventure-works.com">
<Child />
</Root>
Remarks
This operator enables the common idiom of combining a namespace and a local name in the construction of an element or attribute. This idiom provides some of the benefits of having namespace prefixes, in that you can refer to a namespace using a variable that is short. This eliminates syntactic noise in the code that creates XML trees.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기