XmlDocument.LoadXml(String) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 문자열에서 XML 문서를 로드합니다.
public:
virtual void LoadXml(System::String ^ xml);
public virtual void LoadXml(string xml);
abstract member LoadXml : string -> unit
override this.LoadXml : string -> unit
Public Overridable Sub LoadXml (xml As String)
매개 변수
- xml
- String
로드할 XML 문서가 포함된 문자열입니다.
예외
XML에 로드 또는 구문 분석 오류가 있습니다. 이 경우 문서는 비어 있습니다.
예제
다음 예제에서는 개체에 XML을 XmlDocument 로드하고 파일에 저장합니다.
using System;
using System.Xml;
public class Sample {
public static void Main() {
// Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<item><name>wrench</name></item>");
// Add a price element.
XmlElement newElem = doc.CreateElement("price");
newElem.InnerText = "10.95";
doc.DocumentElement.AppendChild(newElem);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
// Save the document to a file and auto-indent the output.
XmlWriter writer = XmlWriter.Create("data.xml", settings);
doc.Save(writer);
}
}
Imports System.Xml
public class Sample
public shared sub Main()
' Create the XmlDocument.
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<item><name>wrench</name></item>")
' Add a price element.
Dim newElem as XmlElement = doc.CreateElement("price")
newElem.InnerText = "10.95"
doc.DocumentElement.AppendChild(newElem)
Dim settings As New XmlWriterSettings()
settings.Indent = True
' Save the document to a file and auto-indent the output.
Dim writer As XmlWriter = XmlWriter.Create("data.xml", settings)
doc.Save(writer)
end sub
end class
설명
기본적으로 메서드는 LoadXml 공백이나 상당한 공백을 유지하지 않습니다.
이 메서드는 DTD(문서 형식 정의)를 구문 분석하지만 DTD 또는 스키마 유효성 검사는 수행하지 않습니다. 유효성 검사를 수행하려면 클래스와 XmlReader 메서드를 사용하여 유효성 XmlReaderSettings 검사 인스턴스를 Create 만들 수 있습니다. 자세한 내용은 XmlReader 참조 페이지의 설명 섹션을 참조하세요.
에서 로드StreamStringTextReaderXmlReader하려면 이 메서드 대신 Load 메서드를 사용합니다.
이 메서드는 DOM(문서 개체 모델)에 대한 Microsoft 확장입니다.