XmlDocument.CreateNode Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Létrehoz egy XmlNode.
Túlterhelések
| Name | Description |
|---|---|
| CreateNode(String, String, String) |
Létrehoz egy XmlNode megadott csomóponttípust, Nameés NamespaceURI. |
| CreateNode(XmlNodeType, String, String) |
Létrehoz egy adott XmlNodeXmlNodeType, Nameés NamespaceURI. |
| CreateNode(XmlNodeType, String, String, String) |
Létrehoz egy XmlNode adott XmlNodeType, Prefix, Nameés NamespaceURI. |
CreateNode(String, String, String)
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
Létrehoz egy XmlNode megadott csomóponttípust, Nameés NamespaceURI.
public:
virtual System::Xml::XmlNode ^ CreateNode(System::String ^ nodeTypeString, System::String ^ name, System::String ^ namespaceURI);
public virtual System.Xml.XmlNode CreateNode(string nodeTypeString, string name, string namespaceURI);
public virtual System.Xml.XmlNode CreateNode(string nodeTypeString, string name, string? namespaceURI);
abstract member CreateNode : string * string * string -> System.Xml.XmlNode
override this.CreateNode : string * string * string -> System.Xml.XmlNode
Public Overridable Function CreateNode (nodeTypeString As String, name As String, namespaceURI As String) As XmlNode
Paraméterek
- nodeTypeString
- String
Az új csomópont sztringverziója XmlNodeType . Ennek a paraméternek az alábbi táblázatban felsorolt értékek egyikének kell lennie.
- name
- String
Az új csomópont minősített neve. Ha a név kettőspontot tartalmaz, a rendszer elemzi PrefixLocalName az összetevőket.
- namespaceURI
- String
Az új csomópont névterének URI-ja.
Válaszok
Az új XmlNode.
Kivételek
A név nem lett megadva, és a XmlNodeType név megadása kötelező; vagy nodeTypeString nem az alább felsorolt sztringek egyike.
Példák
Az alábbi példa létrehoz egy új elemet, és beszúrja a dokumentumba.
using System;
using System.Xml;
public class Sample {
public static void Main() {
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book>" +
" <title>Oberon's Legacy</title>" +
" <price>5.95</price>" +
"</book>");
// Create a new element node.
XmlNode newElem = doc.CreateNode("element", "pages", "");
newElem.InnerText = "290";
Console.WriteLine("Add the new element to the document...");
XmlElement root = doc.DocumentElement;
root.AppendChild(newElem);
Console.WriteLine("Display the modified XML document...");
Console.WriteLine(doc.OuterXml);
}
}
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<book>" & _
" <title>Oberon's Legacy</title>" & _
" <price>5.95</price>" & _
"</book>")
' Create a new element node.
Dim newElem as XmlNode = doc.CreateNode("element", "pages", "")
newElem.InnerText = "290"
Console.WriteLine("Add the new element to the document...")
Dim root as XmlElement = doc.DocumentElement
root.AppendChild(newElem)
Console.WriteLine("Display the modified XML document...")
Console.WriteLine(doc.OuterXml)
end sub
end class
Megjegyzések
A nodeTypeString paraméter megkülönbözteti a kis- és nagybetűket, és az alábbi táblázatban szereplő értékek egyikének kell lennie.
| nodeTypeString | XmlNodeType |
|---|---|
| attribútum | Attribute |
| cdatasection | CDATA |
| hozzászólás | Megjegyzés |
| dokumentum | Dokumentum |
| documentfragment | DocumentFragment |
| documenttype | Dokumentumtípus |
| elem | Elem |
| entityreference | EntityReference |
| feldolgozási struktúra | Feldolgozási utasítás |
| significantwhitespace | JelentősHelyköz |
| SMS | Szöveg |
| térköz | Whitespace |
Bár ez a metódus a dokumentum kontextusában hozza létre az új objektumot, nem adja hozzá automatikusan az új objektumot a dokumentumfához. Az új objektum hozzáadásához explicit módon meg kell hívnia a csomópont beszúrási módszereinek egyikét.
Az alábbi táblázat a W3C Bővíthető korrektúranyelv (XML) 1.0-s javaslatának megfelelően bemutatja, hogy a NodeType[sor] milyen engedélyezett egy másik NodeType[oszlopban].
| Csomópont típusa | Dokumentum | Dokumentumtípus | XML-nyilatkozat | Elem | Attribute | Szöveg | CDATA | Jelölés | EntityReference |
|---|---|---|---|---|---|---|---|---|---|
Document |
no | no | no | no | no | no | no | no | no |
DocumentType |
igen | no | no | no | no | no | no | no | no |
XmlDeclaration |
igen* | no | no | no | no | no | no | no | no |
Element |
igen | no | no | igen | no | no | no | no | Igen† |
Attribute |
no | no | no | Igen‡ | no | no | no | no | no |
Text |
no | no | no | igen | igen | no | no | no | igen |
CDATA |
no | no | no | igen | no | no | no | no | Igen† |
Markup
§ |
igen | no | no | igen | no | no | no | no | no |
EntityReference |
no | no | no | igen | igen | no | no | no | igen |
* A XmlDeclaration csomópontnak a Dokumentum csomópont első gyermekének kell lennie.
§ Markup tartalmazza ProcessingInstruction és Comment csomópontok.
Element† és CDATA csomópontok csak akkor engedélyezettek EntityReference a csomópontokban, ha a EntityReference csomópont nem egy Attribute csomópont gyermeke.
‡ Az attribútumok nem csomópontok Element gyermekei. Az attribútumok egy csomóponthoz tartozó attribútumgyűjteményben Element találhatók.
Ez a metódus a Dokumentumobjektum-modell (DOM) Microsoft bővítménye.
A következőre érvényes:
CreateNode(XmlNodeType, String, String)
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
Létrehoz egy adott XmlNodeXmlNodeType, Nameés NamespaceURI.
public:
virtual System::Xml::XmlNode ^ CreateNode(System::Xml::XmlNodeType type, System::String ^ name, System::String ^ namespaceURI);
public virtual System.Xml.XmlNode CreateNode(System.Xml.XmlNodeType type, string name, string namespaceURI);
public virtual System.Xml.XmlNode CreateNode(System.Xml.XmlNodeType type, string name, string? namespaceURI);
abstract member CreateNode : System.Xml.XmlNodeType * string * string -> System.Xml.XmlNode
override this.CreateNode : System.Xml.XmlNodeType * string * string -> System.Xml.XmlNode
Public Overridable Function CreateNode (type As XmlNodeType, name As String, namespaceURI As String) As XmlNode
Paraméterek
- type
- XmlNodeType
Az XmlNodeType új csomópont.
- name
- String
Az új csomópont minősített neve. Ha a név kettőspontot tartalmaz, akkor a rendszer elemzi az Prefix összetevőketLocalName.
- namespaceURI
- String
Az új csomópont névterének URI-ja.
Válaszok
Az új XmlNode.
Kivételek
A név nem lett megadva, és a XmlNodeType név megadása kötelező.
Példák
Az alábbi példa létrehoz egy új elemet, és beszúrja egy XML-dokumentumba.
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
//Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>");
//Create a new node and add it to the document.
XmlNode elem = doc.CreateNode(XmlNodeType.Element, "price", null);
elem.InnerText = "19.95";
doc.DocumentElement.AppendChild(elem);
Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);
}
}
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
'Create the XmlDocument.
Dim doc As New XmlDocument()
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")
'Create a new node and add it to the document.
Dim elem As XmlNode = doc.CreateNode(XmlNodeType.Element, "price", Nothing)
elem.InnerText = "19.95"
doc.DocumentElement.AppendChild(elem)
Console.WriteLine("Display the modified XML...")
doc.Save(Console.Out)
End Sub
End Class
Megjegyzések
Bár ez a metódus a dokumentum kontextusában hozza létre az új objektumot, nem adja hozzá automatikusan az új objektumot a dokumentumfához. Az új objektum hozzáadásához explicit módon meg kell hívnia a csomópont beszúrási módszereinek egyikét.
Az alábbi táblázat a W3C Bővíthető korrektúranyelv (XML) 1.0-s javaslatának megfelelően bemutatja, hogy a NodeType[sor] milyen engedélyezett egy másik NodeType[oszlopban].
| Csomópont típusa | Dokumentum | Dokumentumtípus | XML-nyilatkozat | Elem | Attribute | Szöveg | CDATA | Jelölés | EntityReference |
|---|---|---|---|---|---|---|---|---|---|
Document |
no | no | no | no | no | no | no | no | no |
DocumentType |
igen | no | no | no | no | no | no | no | no |
XmlDeclaration |
igen* | no | no | no | no | no | no | no | no |
Element |
igen | no | no | igen | no | no | no | no | Igen† |
Attribute |
no | no | no | Igen‡ | no | no | no | no | no |
Text |
no | no | no | igen | igen | no | no | no | igen |
CDATA |
no | no | no | igen | no | no | no | no | Igen† |
Markup§ |
igen | no | no | igen | no | no | no | no | no |
EntityReference |
no | no | no | igen | igen | no | no | no | igen |
* A XmlDeclaration csomópontnak a Dokumentum csomópont első gyermekének kell lennie.
§ Markup tartalmazza ProcessingInstruction és Comment csomópontok.
Element† és CDATA csomópontok csak akkor engedélyezettek EntityReference a csomópontokban, ha a EntityReference csomópont nem egy Attribute csomópont gyermeke.
‡ Az attribútumok nem csomópontok Element gyermekei. Az attribútumok egy csomóponthoz tartozó attribútumgyűjteményben Element találhatók.
Ez a metódus a Dokumentumobjektum-modell (DOM) Microsoft bővítménye.
A következőre érvényes:
CreateNode(XmlNodeType, String, String, String)
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
- Forrás:
- XmlDocument.cs
Létrehoz egy XmlNode adott XmlNodeType, Prefix, Nameés NamespaceURI.
public:
virtual System::Xml::XmlNode ^ CreateNode(System::Xml::XmlNodeType type, System::String ^ prefix, System::String ^ name, System::String ^ namespaceURI);
public virtual System.Xml.XmlNode CreateNode(System.Xml.XmlNodeType type, string prefix, string name, string namespaceURI);
public virtual System.Xml.XmlNode CreateNode(System.Xml.XmlNodeType type, string? prefix, string name, string? namespaceURI);
abstract member CreateNode : System.Xml.XmlNodeType * string * string * string -> System.Xml.XmlNode
override this.CreateNode : System.Xml.XmlNodeType * string * string * string -> System.Xml.XmlNode
Public Overridable Function CreateNode (type As XmlNodeType, prefix As String, name As String, namespaceURI As String) As XmlNode
Paraméterek
- type
- XmlNodeType
Az XmlNodeType új csomópont.
- prefix
- String
Az új csomópont előtagja.
- name
- String
Az új csomópont helyi neve.
- namespaceURI
- String
Az új csomópont névterének URI-ja.
Válaszok
Az új XmlNode.
Kivételek
A név nem lett megadva, és a XmlNodeType név megadása kötelező.
Példák
Az alábbi példa egy új elemet ad hozzá a dokumentumhoz.
using System;
using System.Xml;
public class Sample {
public static void Main() {
// Create a new document containing information about a book
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book>" +
" <title>Oberon's Legacy</title>" +
" <price>5.95</price>" +
"</book>");
// Create a new element node for the ISBN of the book
// It is possible to supply a prefix for this node, and specify a qualified namespace.
XmlNode newElem;
newElem = doc.CreateNode(XmlNodeType.Element, "g", "ISBN", "https://global.ISBN/list");
newElem.InnerText = "1-861001-57-5";
// Add the new element to the document
XmlElement root = doc.DocumentElement;
root.AppendChild(newElem);
// Display the modified XML document
Console.WriteLine(doc.OuterXml);
//Output:
// <book><title>Oberon's Legacy</title><price>5.95</price><g:ISBN xmlns:g="https://global.ISBN/list">1-861001-57-5</g:ISBN></book>
}
}
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<book>" & _
" <title>Oberon's Legacy</title>" & _
" <price>5.95</price>" & _
"</book>")
' Create a new element node.
' It is possible to supply a prefix for this node, and specify a qualified namespace
Dim newElem as XmlNode
newElem = doc.CreateNode(XmlNodeType.Element,"g", "ISBN","https://global.ISBN/list")
newElem.InnerText = "1-861001-57-5"
' Add the new element to the document
Dim root as XmlElement = doc.DocumentElement
root.AppendChild(newElem)
' Display the modified XML document
Console.WriteLine(doc.OuterXml)
' Output:
' <book><title>Oberon's Legacy</title><price>5.95</price><g:ISBN xmlns:g="https://global.ISBN/list">1-861001-57-5</g:ISBN></book>
end sub
end class
Megjegyzések
Bár ez a metódus a dokumentum kontextusában hozza létre az új objektumot, nem adja hozzá automatikusan az új objektumot a dokumentumfához. Az új objektum hozzáadásához explicit módon meg kell hívnia a csomópont beszúrási módszereinek egyikét.
Az alábbi táblázat a W3C Bővíthető korrektúranyelv (XML) 1.0-s javaslatának megfelelően bemutatja, hogy a NodeType[sor] milyen engedélyezett egy másik NodeType[oszlopban].
| Dokumentum | Dokumentumtípus | XML-nyilatkozat | Elem | Attribute | Szöveg | CDATA | Jelölés | EntityReference | |
|---|---|---|---|---|---|---|---|---|---|
Document |
no | no | no | no | no | no | no | no | no |
DocumentType |
igen | no | no | no | no | no | no | no | no |
XmlDeclaration |
igen* | no | no | no | no | no | no | no | no |
Element |
igen | no | no | igen | no | no | no | no | Igen† |
Attribute |
no | no | no | Igen‡ | no | no | no | no | no |
Text |
no | no | no | igen | igen | no | no | no | igen |
CDATA |
no | no | no | igen | no | no | no | no | Igen† |
Markup§ |
igen | no | no | igen | no | no | no | no | no |
EntityReference |
no | no | no | igen | igen | no | no | no | igen |
* Az XmlDeclaration csomópontnak a Dokumentum csomópont első gyermekének kell lennie.
§ Markup tartalmazza ProcessingInstruction és Comment csomópontok.
Element† és CDATA csomópontok csak akkor engedélyezettek EntityReference a csomópontokban, ha a EntityReference csomópont nem egy Attribute csomópont gyermeke.
‡ Az attribútumok nem csomópontok Element gyermekei. Az attribútumok egy csomóponthoz tartozó attribútumgyűjteményben Element találhatók.
Ez a metódus a Dokumentumobjektum-modell (DOM) Microsoft bővítménye.