2013-05-29 2 views
0

xml 스키마를 처음 사용합니다.C에서 xsd 스키마를 사용하여 xml 파일에 데이터 쓰기 #

xsd.exe를 사용하여 내 스키마 용 클래스를 만들 수 있었으며 다음 코드를 생성 할 수있었습니다.

static void Main(string[] args) 
{ 
    var MarketDeclaration_detail = new TransactionsPalletsPalletMarketDeclaration { Set = "", Declaration = "" }; 
    var MarketDeclaration_class = new TransactionsPalletsPalletMarketDeclaration[] { MarketDeclaration_detail }; 

    var PalletLine_detail = new TransactionsPalletsPalletPalletLine { ProductLineNo = "", Quantity = "" }; 
    var PalletLine_class = new TransactionsPalletsPalletPalletLine[] { PalletLine_detail }; 

    var pallet_detail = new TransactionsPalletsPallet { AccreditDate = "", Available = "", Customer = "", MarketDeclaration = MarketDeclaration_class, MixedPltIndicator = "", 
                 PalletLine = PalletLine_class, PalletNo = "", PalletType = "", PartPltIndicator = "", PltSubmisProfile = "", SLOC = "", Status = "", StorageType = "", 
                 Trader = "", TransferInNo = "", TransferOutNo = "", TransferOutOrder = "", TransferOutOrderLine = ""}; 

    var pallet_class = new TransactionsPalletsPallet[] { pallet_detail }; 

    var Materials_detail = new TransactionsReferencesMaterialsMaterial { MaterialNo = "", Trader = "", Brand = "", Variety = "", Size = "", Pack = "", GrowingMethod = "", Grade = "", PackTreatment = "", MarketAttribute = "", Count =""}; 
    var Materials_class = new TransactionsReferencesMaterialsMaterial[] { Materials_detail }; 

    var ProductLines_detail = new TransactionsReferencesProductLinesProductLine { ColourBand = "", Customer = "", ExpiryDate = "", Grower = "", HarvestDate = "", MaterialNo = "", MgmtArea = "", Owner = "", 
                        PackDate = "", Packer = "", PackWeight = "", ProblemRisk = "", ProductionProgram = "", ProductLineNo = "", RPIN = "", Run = "", 
                        SGContract = "", SGContractLine = "", Subdivision = "", SubmisProfile = "", SupplyGroup = "", Trader = ""}; 
    var ProductLines_class = new TransactionsReferencesProductLinesProductLine[] { ProductLines_detail }; 

    var TransfersOut_detail = new TransactionsReferencesTransfersOutTransfer { CarrierID = "", ContainerNo = "", DestinationPort = "", DischargePort = "", DispatchDate = "", DispatchTime = "", ETA = "", From = "", LoadPort = "", ReleaseNo = "", 
                       SealNo = "", Temperature1 = "", Temperature2 = "", TempLogger = "", To = "", TransferNo = "", TransferRef = "", TruckID = "", Vessel = "", Voyage = ""}; 
    // var TransfersOut_class = new TransactionsReferencesTransfersOutTransfer[] { TransfersOut_detail }; 
    TransfersOut(); 

    var references_detail = new TransactionsReferences { Materials = Materials_class, ProductLines = ProductLines_class, TransfersOut = TransfersOut_class }; 
    var references_class = new TransactionsReferences[] { references_detail }; 

    var data1 = new Transactions { Pallets = pallet_class, References = references_class, Serialnumber = "", Timestamp = "" }; 

    var serializer1 = new XmlSerializer(typeof(Transactions)); 

    using (var stream1 = new StreamWriter("C:\\Dave\\xml\\djb2.xml")) 
     serializer1.Serialize(stream1,data1); 
} 

public static TransactionsReferencesTransfersOutTransfer[] TransfersOut_class; 

public static void TransfersOut() 
{ 
    TransactionsReferencesTransfersOutTransfer[] TransfersOut_detail1 = new TransactionsReferencesTransfersOutTransfer[3];    

    for (int i = 0; i < 3; i++) 
    { 
     TransfersOut_detail1[i] = new TransactionsReferencesTransfersOutTransfer { CarrierID = Convert.ToString(i) }; 

     TransfersOut_class = new TransactionsReferencesTransfersOutTransfer[] { TransfersOut_detail1[0], TransfersOut_detail1[1], TransfersOut_detail1[2] }; 
    } 
} 

모두 괜찮습니다. 질문으로

는/문제는 TransferOut_details과도 가지고 내가, 3의 루프에 대한 제한을 준 내 TransfersOut 방법으로

입니다. 그러나 데이터가 데이터베이스에서 반환 될 때까지 얼마나 많은 정보가 있는지 알지 못합니다. 3을 시험으로 사용 하였다.

이 코드를 작성하는 방법을 잘 모르겠습니다. 따라서 모든 행을 XML 파일에 반환하거나 쓰게됩니다.

모든 아이디어/도움을 주시면 감사하겠습니다.

내가 가능한 한 최선의 방법으로 이것을 코딩했는지는 확실합니다.

+0

데이터를 어디서 어떻게 읽으려고하지 않고도 대답 할 수 없습니다. DB에서 오는 경우이 DB에 연결하고 관련 테이블을 읽는 코드가 필요합니다. 일단 생성하면 검색 할 행 수가 자동으로 생성됩니다. – MiMo

+0

예 데이터베이스에서 오는 것입니다. 예 테스트 3을 대체 할 번호를 알려줍니다. I는 말자 어떻게 알 는 I는 루프 외부되어야 알이 광고를 대체 – user2263421

+0

방법이다 TransfersOut_class = 새로운 TransactionsReferencesTransfersOutTransfer [{TransfersOut_detail1 [0] TransfersOut_detail1 [1] TransfersOut_detail1 [2]} ; 모든 생성 된 개체를 전달하는 코드 줄이 있습니다. – user2263421

답변

0

확인. 나는 그것을 잘못한 및이 해결했습니다, 그러나이 개체의 인스턴스로 설정되지 않은 개체 참조에 대한 별도의 질문을 생성 할 수있는 해결하려고하는 새로운 문제가 생성되었습니다.