다음을 통해 공유


방법: InfoPath 2003 개체 모델을 사용하여 응용 프로그램 데이터 액세스

InfoPath 2003 호환 개체 모델에서는 양식의 원본으로 사용하는 XML 문서 및 양식 정의 파일(.xsf) 관련 정보를 포함하여 InfoPath 응용 프로그램에 대한 정보에 액세스하는 데 사용할 수 있는 개체와 컬렉션을 제공합니다. 이 데이터는 Application 인터페이스를 사용하여 인스턴스화되는 InfoPath 개체 모델 계층 구조의 최상위 개체를 통해 액세스합니다.

Microsoft Visual Studio Tools for Applications를 사용하여 만든 InfoPath 2003 호환 관리 코드 양식 서식 파일 프로젝트는 Application 인터페이스의 멤버에 액세스하는 데 사용할 수 있는 양식 코드 클래스의 _Startup 메서드에서 thisApplication 변수를 초기화합니다. 다음 예제에서는 Application 인터페이스의 NameVersion 속성을 사용하여 실행 중인 InfoPath 인스턴스의 이름과 버전 번호를 반환합니다. 이 정보는 UI2 인터페이스의 Alert 메서드를 사용하여 메시지 상자에 표시됩니다.

thisXDocument.UI.Alert("Application name: " + thisApplication.Name +
   "\nApplication version: " + thisApplication.Version);
thisXDocument.UI.Alert("Application name: " & thisApplication.Name & _
   vbNewLine & "Application version: " & thisApplication.Version)

Visual C# 예제에서는 InfoPath 비관리 코드에 의해 경고 메시지 문자열의 \n 문자에 대한 참조가 표준 줄 바꿈으로 렌더링됩니다. 이 줄 바꿈으로 인해 메시지 상자에서 텍스트가 중단되고 새 줄에서 계속됩니다. 현재 환경 및 플랫폼에 대해 정의된 줄 바꿈 값을 명시적으로 사용하려면 다음 예제와 같이 Environment.NewLine 속성을 대신 사용합니다.

thisXDocument.UI.Alert("Application name: " + thisApplication.Name +
   Environment.NewLine + "Application version: " + 
   thisApplication.Version);

양식의 원본으로 사용하는 XML 문서에 포함된 데이터 액세스

개발자는 XDocument 인터페이스를 사용하여 양식의 원본 XML 데이터가 포함된 XML DOM(문서 개체 모델)에 대한 참조를 비롯하여 양식의 원본 XML 문서 관련 정보에 액세스할 수 있습니다.

다음 예제에서는 첫 번째 메시지 상자에는 원본 XML 문서의 변경 여부(IsDirty 속성 사용), 이 문서의 디지털 서명 여부(IsSigned 속성 사용) 등 XDocument 인터페이스에서 사용할 수 있는 일부 데이터가 표시됩니다. 다음 메시지 상자에서는 XDocument 인터페이스의 DOM 속성을 사용하여 양식의 원본 XML 문서의 원본 XML이 표시됩니다.

thisXDocument.UI.Alert("\nIsDirty: " + thisXDocument.IsDirty +
   "\nIsDOMReadOnly: " + thisXDocument.IsDOMReadOnly +
   "\nIsNew: " + thisXDocument.IsNew +
   "\nIsReadOnly: " + thisXDocument.IsReadOnly +
   "\nIsSigned: " + thisXDocument.IsSigned);

thisXDocument.UI.Alert(thisXDocument.DOM.xml);
thisXDocument.UI.Alert("IsDirty: " & thisXDocument.IsDirty & vbNewLine & _
   "IsDOMReadOnly: " & thisXDocument.IsDOMReadOnly & vbNewLine & _
   "IsNew: " & thisXDocument.IsNew & vbNewLine & _
   "IsReadOnly: " & thisXDocument.IsReadOnly & vbNewLine & _
   "IsSigned: " & thisXDocument.IsSigned)

thisXDocument.UI.Alert(thisXDocument.DOM.xml)

앞의 예제에 사용된 xml 속성은 XML DOM(문서 개체 모델)의 속성입니다. XML DOM에 대한 자세한 내용은 MSXML 5.0 SDK 설명서를 참조하십시오.

양식의 양식 정의 파일에 포함된 데이터 액세스

XDocument 인터페이스를 사용하면 양식에 포함된 원본 XML 데이터에 대한 XML DOM 참조를 포함하여 해당 양식의 .xsf 파일에 대한 정보에 액세스할 수도 있습니다. 이 정보는 SolutionObject 인터페이스에 대한 참조를 반환하는 Solution 속성을 사용하여 액세스합니다.

다음 예제에서 첫 번째 경고에는 해당 URI 위치(URI 속성 사용), 버전 번호(Version 속성 사용) 등 SolutionObject 인터페이스를 통해 사용할 수 있는 일부 데이터가 표시됩니다. 다음 경고에서는 SolutionObject 인터페이스의 DOM 속성을 사용하여 .xsf 파일의 원본 XML이 표시됩니다.

thisXDocument.UI.Alert("PackageURL: " +
   thisXDocument.Solution.PackageURL +
   "\nURI: " + thisXDocument.Solution.URI +
   "\nVersion: " + thisXDocument.Solution.Version);

thisXDocument.UI.Alert(thisXDocument.Solution.DOM.xml);
thisXDocument.UI.Alert("PackageURL: " & _
   thisXDocument.Solution.PackageURL & vbNewLine & _
   "URI: " & thisXDocument.Solution.URI & vbNewLine & _
   "Version: " & thisXDocument.Solution.Version)

thisXDocument.UI.Alert(thisXDocument.Solution.DOM.xml)