2011-04-12 3 views
0

편집 : 프로젝트는 오래된 프로젝트이고 아래 코드는 XML을 처리하는 클래스 중 하나입니다.XmlReader.Parse()는 무엇을합니까?

오래된 레거시 응용 프로그램에서 xsd를 가져 오는 질문이 있지만 모든 작업이 다음과 같이됩니다. xmlReader.ParseXml (fileName, outputFile); ProcessXml() 메서드에서.

using System; 
using System.IO; 
using System.Configuration; 
using Utilities; 
namespace JobProcessor 
{ 


public class XmlJob : Job 
{ 
    #region variables 
    private string  ftpServer; 
    private string  ftpUserName; 
    private string  ftpPassWord; 
    private string  ftpDestination; 
    ///<summary>The xml reader used to get validation information from the xmp parsing</summary> 
    protected XmlReader xmlReader = new XmlReader(); 

    private string  outputFile; 


    public XmlJob(string fileName, string type) : base(fileName, type){ 
     ftpServer  = ConfigurationManager.AppSettings[type + "-ftp"]; 
     ftpUserName  = ConfigurationManager.AppSettings[type + "-ftpUser"]; 
     ftpPassWord  = ConfigurationManager.AppSettings[type + "-ftpPass"]; 
     ftpDestination = ConfigurationManager.AppSettings[type + "-ftpDest"]; 
    } 


    protected bool ConfigureXmlReader(){ 
     int recType = 0; 

     try{ 
      //set up the record types (i.e. the elements that trigger a new record in the output 
      while(ConfigurationManager.AppSettings[type + "-RecordType" + recType.ToString("00")] != null){ 
       xmlReader.AddRecordType(ConfigurationManager.AppSettings[type + "-RecordType" + recType.ToString("00")],recType.ToString("00")); 
       recType++; 
      } 
      //store the number of types 
      xmlReader.SetNoRecordTypes(recType); 
     }catch(Exception e){ 
      HandleError("Error loading record types\r\n" + e.ToString() + "\r\n" + e.StackTrace + "\r\n"); 
      return(false); 
     } 

     try{ 
      //set up the fields which make up each record type 
      for(int i=0;i<recType;i++){ 
       xmlReader.AddFieldsList(i,ConfigurationManager.AppSettings[type + "-" + i.ToString("00") + "Fields"]); 
      } 
     }catch(Exception e){ 
      HandleError("Error loading field list\r\n" + e.ToString() + "\r\n" + e.StackTrace + "\r\n"); 
      return(false); 
     } 
     return(true); 
    } 

    public override void RunJob(){ 
     outputFile = Path.Combine(destinationDirectory, Path.GetFileNameWithoutExtension(fileName) + ".flat"); 

     if(!ConfigureXmlReader()){ 
      return; 
     } 

     if(!CheckInputFile()){ 
      return; 
     } 

     if(!ProcessXml()){ 
      return; 
     } 

     if(!Validate()){ 
      return; 
     } 

     if(ftpServer!=null && ftpUserName!=null && ftpPassWord!=null && ftpDestination!=null){ 
      if(!FtpFile()){ 
       return; 
      } 
     } 

     MoveOriginalFile(); 
    } 


    protected virtual bool Validate(){ 
     return(true); 
    } 

    protected bool ProcessXml(){ 
     /* 
     * Process the xml file into a delimited format 
     */ 

     try{ 
      xmlReader.ParseXml(fileName,outputFile); 
     }catch(Exception e){ 
      HandleError("Error parsing XML file\r\n" + e.ToString() + "\r\n" + e.StackTrace + "\r\n"); 
      return(false); 
     } 
     return(true); 
    } 
    protected bool FtpFile(){ 
     try{ 
      FtpMethods.UploadFile(ftpServer,ftpUserName,ftpPassWord,outputFile,ftpDestination); 
     }catch(Exception e){ 
      HandleError("Error FTPing file\r\n" + e.ToString() + "\r\n" + e.StackTrace + "\r\n"); 
      return(false); 
     } 
     return(true); 
    } 

    #endregion 
} 

}

정확히이 명령은 무엇입니까? F1은 아무 것도 찾지 못했고 Google 검색을 통해 많은 xmlTextReaders를 얻을 수 있습니다.

+3

여기서 xmlReader 인스턴스의 유형은 무엇입니까? –

+0

표시된 코드가 컴파일되지 않습니다. 'XmlReader'는 추상 클래스입니다. –

+0

실제 코드를 게시하십시오. 'XmlReader'는 추상 클래스이며 인스턴스화 할 수 없습니다. –

답변

2

XMLReader 유형이 여기 것 같다 라이브러리의 XMLReader 형식이 아니고 형식의 라이브러리가 아닙니다.

1

XmlReader 클래스에는 Parse 메서드가 없습니다. 코드에 선언 된 변수 xmlReader의 런타임 유형을 확인한 다음 msdn을 다시 확인하십시오.

그렇지 않으면 XDocument.Parse을 의미합니다.

업데이트 영업 이익의 편집
후 나는 전체 BCL의 모든 ParseXml을 찾기 위해 관리하지 않았다.

갱신 2 영업 이익의 편집 후
XmlReader 클래스는 추상적이고 코드에 선언하여 사용할 수 없습니다.
System.Xml 네임 스페이스가 파일로 가져 오지 않았기 때문에 코드의 xmlReader 변수 유형이 Utilities 네임 스페이스의 어딘가에서 선언 된 것으로 결론을 내릴 수밖에 없으므로 아무도 (또는 다른 사람) 코딩했습니다.

보조 메모로 XmlReader 또는 IDisposable 인터페이스를 구현하는 다른 유형을 사용하는 경우 처분 (view link)을 처리해야합니다.

2

편집는 : 그것은 XmlReader를 같이 보이는 코드를보고 한 후하여 XDocument 주위 가능성이 가장 높은 랩이

아래에 설명 된대로 사용자 정의 클래스 (에서 System.Xml에 대한 using 문이 존재하지 않는 점을 감안)입니다 그것은 잘못 될 수있다 명명 된 Xml 함께 작동하는 유일한 Parse 메서드는 System.Xml.Linq 네임 스페이스의 모든 XmlElements입니다. 나는.

XDocument.Parse(xmlString); 

이 XML을 구문 분석, 그것은 유효한 XMLDocument로인지 확인하고 만약 그렇다면 그것은하여 XDocument으로로드 (또는 어떤 요소 것은)

2

사용중인 XmlReader 클래스는 맞춤 클래스입니다. 대체로 Utilities.XmlReader 일 가능성이 큽니다. 우리는 그것에 대해 아무 말도 할 수 없습니다. 왜냐하면 그것은 당신이나 동료가 작성한 수업이기 때문입니다.

2

MSDN/F1 도움말에서 메서드 정의에 대한 정보를 제공하지 않는다면 ParseXml이 XmlReader의 확장 메서드라고 생각하겠습니까? 또는 아마도 XmlReader에서 서브 클래 싱 된 코드 작성자가이 메서드를 추가했습니다.