मैं वर्तमान में कुछ एक्सएमएल फाइलों के लिए वर्जनिंग कार्यक्षमता पर काम कर रहा हूं जिनके साथ मैं काम कर रहा हूं। मूल कार्यप्रवाह यह है कि जैसे ही XML फ़ाइल को पार्स किया जाता है, इसे ऑर्डर द्वारा तोड़ दिया जाता है और फिर डेटाबेस तालिका में डाल दिया जाता है, फिर XML के नवीनतम संस्करण के आधार पर निकाला जाता है और उस ऑब्जेक्ट में फिर से जोड़ा जाता है जिसके साथ मैं काम कर सकता हूं।

यह एक उदाहरण है कि एक ऑर्डर एक्सएमएल जैसा दिखता है (आप बस इसके माध्यम से स्किम कर सकते हैं - यह वही है जिसके साथ मैं काम कर रहा हूं):

<Order IsEmpty="N">
  <OrderNum>13903899</OrderNum>
  <AmtUOM>US$</AmtUOM>
  <CompanyUnit>Y</CompanyUnit>
  <CreatedBy>PenskeTruckLeasing</CreatedBy>
  <Opened>05/01/2018</Opened>
  <Priority>5</Priority>
  <ShopID>DE PERE</ShopID>
  <TaxOverride>F</TaxOverride>
  <UnitID>892</UnitID>
  <Vendor>64657200-7542</Vendor>
  <NonCompUnitID />
  <InvOrder IsEmpty="N">
    <InvType>REPAIR</InvType>
    <PONum>7542-136815</PONum>
  </InvOrder>
  <RepOrder IsEmpty="N">
    <RepSite>FACILITY</RepSite>
    <RepClass>NONSCHEDULED</RepClass>
    <Opened>05/01/2018</Opened>
    <Closed>05/02/2018</Closed>
  </RepOrder>
  <OrderSec IsEmpty="N">
    <Billable>Y</Billable>
    <SystemCode>001</SystemCode>
    <AssemblyCode>001</AssemblyCode>
    <PartCode>219</PartCode>
    <WorkAccomplishedCode>003</WorkAccomplishedCode>
    <CompCode>001</CompCode>
    <ActionCode>10</ActionCode>
    <Complaint>PM</Complaint>
    <CompltDate>05/02/2018 07:56:38 </CompltDate>
    <PTLComplaint>AC FILTER</PTLComplaint>
    <PTLCause>PLUGGED</PTLCause>
    <PTLCorrection>REPLACE FILTER AIR CONDITIONER</PTLCorrection>
    <DelReason />
    <ExtWarranty>N</ExtWarranty>
    <Opened>05/01/2018 11:39:06 </Opened>
    <Priority>5</Priority>
    <RepReason>PM</RepReason>
    <SecComment>AC FILTER;AIR CONDITIONING, HEATING   VENTILATING SYSTEM;INV#:0013903899</SecComment>
    <SectionNum />
    <TaxOverride />
    <WarrType />
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>14.99</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>001</SystemCode>
      <AssemblyCode>001</AssemblyCode>
      <PartCode>219</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>001</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>AIR FILTER PANEL</Descrip>
      <Hours>0</Hours>
      <LineTotal>14.99</LineTotal>
      <LineType>PART</LineType>
      <Mechanic />
      <PartID>AF55777</PartID>
      <QtyReqd>1.0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>31.02</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>001</SystemCode>
      <AssemblyCode>001</AssemblyCode>
      <PartCode>219</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>001</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>LABOR</Descrip>
      <Hours>1</Hours>
      <LineTotal>31.02</LineTotal>
      <LineType>LABOR</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>1.37</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>001</SystemCode>
      <AssemblyCode>001</AssemblyCode>
      <PartCode>219</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>001</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>SALES TAX</Descrip>
      <Hours />
      <LineTotal>1.37</LineTotal>
      <LineType>TAX</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>1</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
  </OrderSec>
  <OrderSec IsEmpty="N">
    <Billable>Y</Billable>
    <SystemCode>002</SystemCode>
    <AssemblyCode>010</AssemblyCode>
    <PartCode>055</PartCode>
    <WorkAccomplishedCode>003</WorkAccomplishedCode>
    <CompCode>002</CompCode>
    <ActionCode>10</ActionCode>
    <Complaint>PM</Complaint>
    <CompltDate>05/02/2018 07:56:38 </CompltDate>
    <PTLComplaint>MIRROR SWITCH</PTLComplaint>
    <PTLCause>FAILED</PTLCause>
    <PTLCorrection>REPLACE MIRROR POWER DIRECTIONAL CONTROL SWITCH</PTLCorrection>
    <DelReason />
    <ExtWarranty>N</ExtWarranty>
    <Opened>05/01/2018 11:39:06 </Opened>
    <Priority>5</Priority>
    <RepReason>PM</RepReason>
    <SecComment>MIRROR SWITCH;CAB   SHEET METAL;INV#:0013903899</SecComment>
    <SectionNum />
    <TaxOverride />
    <WarrType />
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>43.51</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>002</SystemCode>
      <AssemblyCode>010</AssemblyCode>
      <PartCode>055</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>002</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>SWITCH,MOTOR,REMOTE CONTR...</Descrip>
      <Hours>0</Hours>
      <LineTotal>43.51</LineTotal>
      <LineType>PART</LineType>
      <Mechanic />
      <PartID>DTL 15829700</PartID>
      <QtyReqd>1.0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>38.77</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>002</SystemCode>
      <AssemblyCode>010</AssemblyCode>
      <PartCode>055</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>002</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>LABOR</Descrip>
      <Hours>1</Hours>
      <LineTotal>38.77</LineTotal>
      <LineType>LABOR</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>3.98</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>002</SystemCode>
      <AssemblyCode>010</AssemblyCode>
      <PartCode>055</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>002</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>SALES TAX</Descrip>
      <Hours />
      <LineTotal>3.98</LineTotal>
      <LineType>TAX</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>1</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
  </OrderSec>
  <OrderSec IsEmpty="N">
    <Billable>Y</Billable>
    <SystemCode>002</SystemCode>
    <AssemblyCode>035</AssemblyCode>
    <PartCode>015</PartCode>
    <WorkAccomplishedCode>003</WorkAccomplishedCode>
    <CompCode>002</CompCode>
    <ActionCode>10</ActionCode>
    <Complaint>PM</Complaint>
    <CompltDate>05/02/2018 07:56:38 </CompltDate>
    <PTLComplaint>WIPERS</PTLComplaint>
    <PTLCause>STREAK</PTLCause>
    <PTLCorrection>REPLACE WINDSHIELD WIPER BLADE</PTLCorrection>
    <DelReason />
    <ExtWarranty>N</ExtWarranty>
    <Opened>05/01/2018 11:39:06 </Opened>
    <Priority>5</Priority>
    <RepReason>PM</RepReason>
    <SecComment>WIPERS;CAB   SHEET METAL;INV#:0013903899</SecComment>
    <SectionNum />
    <TaxOverride />
    <WarrType />
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>3.36</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>002</SystemCode>
      <AssemblyCode>035</AssemblyCode>
      <PartCode>015</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>002</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>BLADE,WIPER</Descrip>
      <Hours>0</Hours>
      <LineTotal>6.72</LineTotal>
      <LineType>PART</LineType>
      <Mechanic />
      <PartID>ABP N82 7622</PartID>
      <QtyReqd>2.0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>23.26</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>002</SystemCode>
      <AssemblyCode>035</AssemblyCode>
      <PartCode>015</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>002</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>LABOR</Descrip>
      <Hours>1</Hours>
      <LineTotal>23.26</LineTotal>
      <LineType>LABOR</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>.61</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>002</SystemCode>
      <AssemblyCode>035</AssemblyCode>
      <PartCode>015</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>002</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>SALES TAX</Descrip>
      <Hours />
      <LineTotal>.61</LineTotal>
      <LineType>TAX</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>1</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
  </OrderSec>
  <OrderSec IsEmpty="N">
    <Billable>Y</Billable>
    <SystemCode>002</SystemCode>
    <AssemblyCode>042</AssemblyCode>
    <PartCode>001</PartCode>
    <WorkAccomplishedCode>024</WorkAccomplishedCode>
    <CompCode>002</CompCode>
    <ActionCode>15</ActionCode>
    <Complaint>PM</Complaint>
    <CompltDate>05/02/2018 07:56:38 </CompltDate>
    <PTLComplaint>DECK PLATE</PTLComplaint>
    <PTLCause>LOSE</PTLCause>
    <PTLCorrection>REPAIR DECK PLATE/CROSSWALK AND MOUNTING BRACKETS</PTLCorrection>
    <DelReason />
    <ExtWarranty>N</ExtWarranty>
    <Opened>05/01/2018 11:39:06 </Opened>
    <Priority>5</Priority>
    <RepReason>PM</RepReason>
    <SecComment>DECK PLATE;REPAIR DECK PLATE/CROSSWALK AND MOUNTING BRACKETS;INV#:0013903899</SecComment>
    <SectionNum />
    <TaxOverride />
    <WarrType />
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>77.54</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>002</SystemCode>
      <AssemblyCode>042</AssemblyCode>
      <PartCode>001</PartCode>
      <WorkAccomplishedCode>024</WorkAccomplishedCode>
      <CompCode>002</CompCode>
      <ActionCode>15</ActionCode>
      <Descrip>LABOR</Descrip>
      <Hours>.50</Hours>
      <LineTotal>38.77</LineTotal>
      <LineType>LABOR</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
  </OrderSec>
  <OrderSec IsEmpty="N">
    <Billable>Y</Billable>
    <SystemCode>017</SystemCode>
    <AssemblyCode>001</AssemblyCode>
    <PartCode>020</PartCode>
    <WorkAccomplishedCode>003</WorkAccomplishedCode>
    <CompCode>017</CompCode>
    <ActionCode>10</ActionCode>
    <Complaint>PM</Complaint>
    <CompltDate>05/02/2018 07:56:38 </CompltDate>
    <PTLComplaint>LEFT REAR DRIVE TIRE</PTLComplaint>
    <PTLCause>MISSING TREAD SECTION</PTLCause>
    <PTLCorrection>REPLACE DRIVE TIRE(S)-3RD AXLE LEFT</PTLCorrection>
    <DelReason />
    <ExtWarranty>N</ExtWarranty>
    <Opened>05/01/2018 11:39:06 </Opened>
    <Priority>5</Priority>
    <RepReason>PM</RepReason>
    <SecComment>LEFT REAR DRIVE TIRE;REAR TIRES;INV#:0013903899</SecComment>
    <SectionNum />
    <TaxOverride />
    <WarrType />
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>46.52</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>017</SystemCode>
      <AssemblyCode>001</AssemblyCode>
      <PartCode>020</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>017</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>LABOR</Descrip>
      <Hours>1</Hours>
      <LineTotal>46.52</LineTotal>
      <LineType>LABOR</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
  </OrderSec>
  <OrderSec IsEmpty="N">
    <Billable>Y</Billable>
    <SystemCode>034</SystemCode>
    <AssemblyCode>004</AssemblyCode>
    <PartCode>021</PartCode>
    <WorkAccomplishedCode>003</WorkAccomplishedCode>
    <CompCode>034</CompCode>
    <ActionCode>10</ActionCode>
    <Complaint>PM</Complaint>
    <CompltDate>05/02/2018 07:56:38 </CompltDate>
    <PTLComplaint>BACK UP LIGHT</PTLComplaint>
    <PTLCause>BLOWN</PTLCause>
    <PTLCorrection>REPLACE CLEARANCE/MARKER LIGHT CAB AND CHASSIS ONLY-REAR RT</PTLCorrection>
    <DelReason />
    <ExtWarranty>N</ExtWarranty>
    <Opened>05/01/2018 11:39:06 </Opened>
    <Priority>5</Priority>
    <RepReason>PM</RepReason>
    <SecComment>BACK UP LIGHT;LIGHTING SYSTEM;INV#:0013903899</SecComment>
    <SectionNum />
    <TaxOverride />
    <WarrType />
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>31.02</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>034</SystemCode>
      <AssemblyCode>004</AssemblyCode>
      <PartCode>021</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>034</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>LABOR</Descrip>
      <Hours>1</Hours>
      <LineTotal>31.02</LineTotal>
      <LineType>LABOR</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>.33</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>034</SystemCode>
      <AssemblyCode>004</AssemblyCode>
      <PartCode>021</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>034</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>SALES TAX</Descrip>
      <Hours />
      <LineTotal>.33</LineTotal>
      <LineType>TAX</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>1</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>3.59</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>034</SystemCode>
      <AssemblyCode>004</AssemblyCode>
      <PartCode>021</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>034</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>LAMP,BACKUP</Descrip>
      <Hours>0</Hours>
      <LineTotal>3.59</LineTotal>
      <LineType>PART</LineType>
      <Mechanic />
      <PartID>TL  40204</PartID>
      <QtyReqd>1.0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
  </OrderSec>
  <OrderSec IsEmpty="N">
    <Billable>Y</Billable>
    <SystemCode>041</SystemCode>
    <AssemblyCode>001</AssemblyCode>
    <PartCode>005</PartCode>
    <WorkAccomplishedCode>003</WorkAccomplishedCode>
    <CompCode>041</CompCode>
    <ActionCode>10</ActionCode>
    <Complaint>PM</Complaint>
    <CompltDate>05/02/2018 07:56:38 </CompltDate>
    <PTLComplaint>LOW POWER</PTLComplaint>
    <PTLCause>FILTER</PTLCause>
    <PTLCorrection>COMPLETE AF - REPLACE AIR FILTER MAIN ENGINE (INCLUDES BOTH ON M2'S)</PTLCorrection>
    <DelReason />
    <ExtWarranty>N</ExtWarranty>
    <Opened>05/01/2018 11:39:06 </Opened>
    <Priority>5</Priority>
    <RepReason>PM</RepReason>
    <SecComment>LOW POWER;AIR INTAKE SYSTEM;INV#:0013903899</SecComment>
    <SectionNum />
    <TaxOverride />
    <WarrType />
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>57.70</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>041</SystemCode>
      <AssemblyCode>001</AssemblyCode>
      <PartCode>005</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>041</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>FILTER,ELEMENT,AIR FILTER</Descrip>
      <Hours>0</Hours>
      <LineTotal>57.70</LineTotal>
      <LineType>PART</LineType>
      <Mechanic />
      <PartID>AF27879</PartID>
      <QtyReqd>1.0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>31.02</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>041</SystemCode>
      <AssemblyCode>001</AssemblyCode>
      <PartCode>005</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>041</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>LABOR</Descrip>
      <Hours>1</Hours>
      <LineTotal>31.02</LineTotal>
      <LineType>LABOR</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>5.28</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>041</SystemCode>
      <AssemblyCode>001</AssemblyCode>
      <PartCode>005</PartCode>
      <WorkAccomplishedCode>003</WorkAccomplishedCode>
      <CompCode>041</CompCode>
      <ActionCode>10</ActionCode>
      <Descrip>SALES TAX</Descrip>
      <Hours />
      <LineTotal>5.28</LineTotal>
      <LineType>TAX</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>1</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
  </OrderSec>
  <OrderSec IsEmpty="N">
    <Billable>Y</Billable>
    <SystemCode>053</SystemCode>
    <AssemblyCode>004</AssemblyCode>
    <PartCode>001</PartCode>
    <WorkAccomplishedCode>013</WorkAccomplishedCode>
    <CompCode>053</CompCode>
    <ActionCode>95</ActionCode>
    <Complaint>PM</Complaint>
    <CompltDate>05/02/2018 07:56:38 </CompltDate>
    <PTLComplaint>CAMPAIGN</PTLComplaint>
    <PTLCause>REQUIRED</PTLCause>
    <PTLCorrection>COMPLETE OTH KIDDE CAMPAIGN - BUL#50-117 - REPLACE FIRE EXTINGUISHER</PTLCorrection>
    <DelReason />
    <ExtWarranty>N</ExtWarranty>
    <Opened>05/01/2018 11:39:06 </Opened>
    <Priority>5</Priority>
    <RepReason>PM</RepReason>
    <SecComment>CAMPAIGN;EXPENDABLES;INV#:0013903899</SecComment>
    <SectionNum />
    <TaxOverride />
    <WarrType />
    <OrderLine IsEmpty="N">
      <AdditType />
      <AfterMarket />
      <ChgAmt>77.50</ChgAmt>
      <ChgCateg>STANDARD</ChgCateg>
      <ChgDate>05/02/2018 07:56:38 </ChgDate>
      <ChgUOM>US$</ChgUOM>
      <SystemCode>053</SystemCode>
      <AssemblyCode>004</AssemblyCode>
      <PartCode>001</PartCode>
      <WorkAccomplishedCode>013</WorkAccomplishedCode>
      <CompCode>053</CompCode>
      <ActionCode>95</ActionCode>
      <Descrip>LABOR</Descrip>
      <Hours>.10</Hours>
      <LineTotal>7.75</LineTotal>
      <LineType>LABOR</LineType>
      <Mechanic />
      <PartID />
      <QtyReqd>0</QtyReqd>
      <QtyUOM />
      <Taxable />
      <TaxAmt />
      <VendorLine />
    </OrderLine>
  </OrderSec>
</Order>

अब, एक सामान्य क्रम में इनमें से लगभग 60 खंड होते हैं जब यह आता है। लंबी कहानी संक्षेप में, मुझे इन अनुभागों में से एक्सएमएल को फिर से इकट्ठा करने की आवश्यकता है।

अब तक मैंने xml ऑब्जेक्ट बनाया है और पहला नोड बनाया है (जो कि उस फ़ाइल में से केवल एक है), जो एक VendorInvoice है।

# new xml
[xml]$Newxml = New-Object System.Xml.XmlDocument
$newxml.LoadXml("<?xml version=`"1.0`" encoding=`"us-ascii`"?><VendorInvoices></VendorInvoices>")

मुझे इन आदेशों में से प्रत्येक को विक्रेता चालान में विक्रेता चालान नोड में जोड़ने की आवश्यकता है, जिसे मैं यहां करने का प्रयास कर रहा हूं:

foreach($VendorInvoice in $xml.VendorInvoices)
{
    foreach($Order in $VendorInvoices.Order)
    {
        $newxml.AppendChild($Order.OuterXml)
        $newxml.Save($Newxml)
    }
}

हालांकि, ऐसा करना वेंडरइनवॉइस नोड के तहत कुछ भी पॉप्युलेट नहीं करता है:

xml                               VendorInvoices
---                               --------------
version="1.0" encoding="us-ascii" 

क्या किसी को पता है कि मैं यहाँ कहाँ गलत हो रहा हूँ? इस प्रक्रिया के लिए मुझे एक्सएमएल फाइलों से बहुत कुछ हटाने की आवश्यकता है, लेकिन यह पहला उदाहरण है जहां मुझे एक्सएमएल फाइल बनानी पड़ी है।

यदि आवश्यक हो तो मैं और जानकारी प्रदान कर सकता हूं।

1
Matt 18 जून 2018, 21:58

1 उत्तर

सबसे बढ़िया उत्तर

सरलीकृत इनपुट के साथ एक कार्यशील उदाहरण यहां दिया गया है:

# The input document.
[xml] $xml = @'
<VendorInvoices>
  <Order>
    <OrderNum>1</OrderNum>
  </Order>
  <Order>
    <OrderNum>2</OrderNum>
  </Order>
</VendorInvoices>
'@

# Create the target XML document.
# Add a <dummy /> child element to <VendorVoices>, so we
# can get a reference to child element <VendorVoices> with dot notation below.
[xml] $newXml = @'
<?xml version="1.0" encoding="us-ascii"?>
<VendorInvoices><dummy/></VendorInvoices>
'@

# Get a referene to the new document's <VendorInvoices> element.
$newVendorInvoices = $newXml.VendorInvoices
$newVendorInvoices.Removeall() # Remove the dummy child node.

# Loop over all <Order> child elements of the original document's
# <VendorInvoices> element and add them to the target document's
# <VendorInvoices> element.
foreach ($order in $xml.VendorInvoices.Order) {
  # Import the order at hand into the new document and append it to the
  # <VendorInvoices> element. Note: .AppendChild() modifies the document in-place
  # and *also returns* the new child node; we assign to $null to suppress this output.
  $null = $newVendorInvoices.AppendChild($newXml.ImportNode($order, $true))
}

# Use Format-Custom to print a quick-and-dirty visualization of the document. 
# If you want to save the document to a new file, use, e.g., $newXml.Save("$PWD/new.xml")
$newXml | Format-Custom

उपरोक्त उपज:

class XmlDocument
{
  xml = version="1.0" encoding="us-ascii"
  VendorInvoices = 
    class XmlElement
    {
      Order = 
        [
          class XmlElement
          {
            OrderNum = 1
          }
          class XmlElement
          {
            OrderNum = 2
          }
        ]

    }
}

जहां तक ​​आपने क्या प्रयास किया का प्रश्न है:

  • आपके आंतरिक लूप में एक टाइपो है: $VendorInvoices $VendorInvoice होना चाहिए।

  • आप गलती से $Order को चाइल्ड एलिमेंट <VendorInvoices> के बजाय लक्ष्य दस्तावेज़ के रूट (दस्तावेज़) तत्व में जोड़ने का प्रयास कर रहे हैं।

  • .OuterXml प्रॉपर्टी का मान - एक [string] - .AppendChild() का उपयोग करके मौजूदा तत्व को जोड़ना - जो एक [System.Xml.XmlNode] इंस्टेंस की अपेक्षा करता है - एक अलग तत्व के लिए काम नहीं करता है।

  • $newXml.Save($newXml) व्यर्थ है: इन-मेमोरी DOM जोड़तोड़ के लिए आपको किसी सेव ऑपरेशन की आवश्यकता नहीं है, और यदि आप किसी फ़ाइल में सहेजना चाहते हैं, तो आपको एक आउटपुट फ़ाइल पथ; वास्तव में, यह $newXml का स्ट्रिंगिफिकेशन है - जो स्ट्रिंग अक्षर 'System.Xml.XmlDocument' है - जिसे यहां आउटपुट फ़ाइल नाम के रूप में व्याख्या किया गया है।

1
mklement0 19 जून 2018, 15:59