Export (0) Print
Expand All

XmlDocument.CreateElement Method (String, String)

Creates an XmlElement with the qualified name and NamespaceURI.

Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)

public XmlElement CreateElement (
	string qualifiedName,
	string namespaceURI
)
public XmlElement CreateElement (
	String qualifiedName, 
	String namespaceURI
)
public function CreateElement (
	qualifiedName : String, 
	namespaceURI : String
) : XmlElement
Not applicable.

Parameters

qualifiedName

The qualified name of the element. If the name contains a colon then the Prefix property will reflect the part of the name preceding the colon and the LocalName property will reflect the part of the name after the colon. The qualified name cannot include a prefix of'xmlns'.

namespaceURI

The namespace URI of the element.

Return Value

The new XmlElement.

The following C# code

 XmlElement elem;
 elem=doc.CreateElement("xy:item", "urn:abc");

results in an element that is equivalent to the following XML text.

<xy:item
       xmlns:xy="urn:abc"/>

Although this method creates the new object in the context of the document, it does not automatically add the new object to the document tree. To add the new object, you must explicitly call one of the node insert methods.

According to the W3C Extensible Markup Language (XML) 1.0 recommendation (www.w3.org/TR/1998/REC-xml-19980210), Element nodes are allowed within Document and Element nodes, and in EntityReference nodes when the EntityReference node is not a child of an Attribute node.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2015 Microsoft