다음을 통해 공유


InfoPath 2003 개체 모델을 사용하여 MSXML 및 System.Xml 작업

InfoPath 2003 개체 모델에서 작동하는 양식 서식 파일 프로젝트는 내부적으로 Microsoft XML Core Services(MSXML)를 사용하여 XML 작업을 수행합니다. 관리 코드에서는 .NET Framework 클래스 라이브러리의 System.Xml 네임스페이스에서 제공하는 XML 지원을 사용하면 좀 더 편리한 경우가 있습니다. MSXML과 System.Xml은 개체를 있는 그대로 교환할 수 없으므로 InfoPath와 다른 관리 코드 간에 XML 데이터를 전달해야 할 때마다 XML 데이터를 변환해야 합니다. 이 항목에서 설명하는 기술을 사용하면 System.Xml 개체의 XML 데이터를 InfoPath 양식 코드와 교환할 수 있습니다.

InfoPath 2003 개체 모델을 사용하는 관리 코드 프로젝트에서 System.Xml 네임스페이스의 멤버를 사용하려면 Microsoft Visual Studio Tools for Applications를 실행한 후 참조 추가 대화 상자의 .NET 탭에서 System.Xml에 대한 참조를 추가해야 합니다.

참고

  • MSXML에 대한 참조 정보를 보려면 MSXML SDK를 참조하십시오.

  • Microsoft.Office.Interop.InfoPath.SemiTrust 네임스페이스에 의해 래핑된 MSXML 개체 모델의 멤버는 관리 코드 양식 서식 파일의 양식 코드에 대리자로 할당할 수 없습니다.

  • Microsoft.Office.InfoPath 네임스페이스의 멤버가 제공하는 개체 모델을 사용하도록 양식 서식 파일의 코드를 업데이트하면 System.Xml이 있는 그대로 사용됩니다. 그러나 이렇게 하는 경우 새 개체 모델을 사용하도록 모든 코드를 수동으로 변환해야 합니다. 새 개체 모델을 사용하도록 양식 서식 파일을 변환하려면 양식 옵션 대화 상자의 프로그래밍 범주에서 OM 업그레이드를 클릭합니다.

System.Xml에서 전체 XML DOM(문서 개체 모델) 로드

다음 코드 예제에서는 InfoPath CreateDOM 메서드와 Microsoft.Office.Interop.InfoPath.SemiTrust 네임스페이스의 멤버에 의해 래핑된 Microsoft XML Core Services의 멤버를 사용하여 System.Xml 코드에서 전체 XML DOM을 로드하는 방법을 보여 줍니다.

다음 예제를 실행하려면 양식 코드 모듈의 선언 섹션에 System.Xml에 대한 using 또는 Imports 지시문이 필요합니다. 그리고 XmlDocument 클래스의 Load 메서드에 System.Security.Permissions.FileIOPermission이 필요하므로 양식 옵션 대화 상자의 보안 및 신뢰 범주를 사용하여 양식 서식 파일의 보안 수준을 전체 신뢰로 구성해야 합니다.

// Create a System.Xml XmlDocument and load an XML file.
XmlDocument doc = new XmlDocument();
doc.Load("c:\\temp\\MyFile.xml");

// Create an MSXML DOM object.
IXMLDOMDocument newDoc = thisXDocument.CreateDOM();

// Load the DOM with the XML from the System.XML object.
newDoc.loadXML(doc.DocumentElement.OuterXml);
' Create a System.Xml XmlDocument and load an XML file.
Dim doc As XmlDocument = New XmlDocument()
doc.Load("c:\temp\MyFile.xml");

' Create an MSXML DOM object.
Dim newDoc As IXMLDOMDocument = thisXDocument.CreateDOM()

' Load the DOM with the XML from the System.XML object.
newDoc.loadXML(doc.DocumentElement.OuterXml)

System.Xml에서 단일 노드 로드

다음 코드 예제에서는 래핑된 MSXML createNode 메서드를 사용하여 System.Xml.XmlElement에서 단일 노드를 복제하는 방법을 보여 줍니다.

다음 예제를 실행하려면 양식 코드 모듈의 선언 섹션에 System.Xml에 대한 using 또는 Imports 지시문이 필요합니다.

// This function takes a System.Xml XmlElement object and 
// an MSXML IXMLDOMDocument object, and returns an MSXML 
// IXMLDOMNode object that is a copy of the XmlElement object.
public IXMLDOMNode CloneSystemXmlElementToMsxml(
   XmlElement systemXmlElement, IXMLDOMDocument msxmlDocument)

{
   IXMLDOMNode msxmlResultNode;

   // Create a new element from the MSXML DOM using the same 
   // namespace as the XmlElement.
   msxmlResultNode = msxmlDocument.createNode(
      DOMNodeType.NODE_ELEMENT, 
      systemXmlElement.Name, 
      systemXmlElement.NamespaceURI);

   // Set the element's value.
   msxmlResultNode.text = systemXmlElement.Value.ToString();

   return msxmlResultNode;
}
' This function takes a System.Xml XmlElement object and 
' an MSXML IXMLDOMDocument object, and returns an MSXML 
' IXMLDOMNode object that is a copy of the XmlElement object.
Public Function CloneSystemXmlElementToMsxml(_
   XmlElement systemXmlElement, _
   IXMLDOMDocument msxmlDocument) As IXMLDOMNode

   Dim msxmlResultNode As IXMLDOMNode

   ' Create a new element from the MSXML DOM using the same 
   ' namespace as the XmlElement.
   msxmlResultNode = msxmlDocument.createNode(_
      DOMNodeType.NODE_ELEMENT, _
      systemXmlElement.Name, _
      systemXmlElement.NamespaceURI)

   ' Set the element's value.
   msxmlResultNode.text = systemXmlElement.Value.ToString()

   Return msxmlResultNode
End Function