Sunday, 10 January 2016

XML : How do read selected Fields from Complex XML Document with PHP

I have a 5 different XML Documents with Similar Structures but each with varying data in them. They are all in the following format.

   <xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'      xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'      xmlns:rs='urn:schemas-microsoft-com:rowset'      xmlns:z='#RowsetSchema'>  <s:Schema id='RowsetSchema'>      <s:ElementType name='row' content='eltOnly' rs:CommandTimeout='30'>          <s:AttributeType name='WorkType' rs:number='1' rs:writeunknown='true'>              <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='20' rs:maybenull='false'/>          </s:AttributeType>          <s:AttributeType name='WorkDescription' rs:number='2' rs:nullable='true' rs:writeunknown='true'>              <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='100'/>          </s:AttributeType>          <s:AttributeType name='NotesReqd' rs:number='3' rs:nullable='true' rs:writeunknown='true'>              <s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true'/>          </s:AttributeType>          <s:AttributeType name='EmpType' rs:number='4' rs:writeunknown='true'>              <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='1' rs:fixedlength='true' rs:maybenull='false'/>          </s:AttributeType>          <s:extends type='rs:rowbase'/>      </s:ElementType>  </s:Schema>  <rs:data>      <z:row WorkType='6530' WorkDescription='Site Subbies - Delivery' NotesReqd='0' EmpType='S'/>      <z:row WorkType='6550' WorkDescription='Site Subbies - Travel' NotesReqd='0' EmpType='S'/>      <z:row WorkType='6510' WorkDescription='Site Subbies - Measure' NotesReqd='0' EmpType='S'/>      <z:row WorkType='6520' WorkDescription='Site Subbies - Management' NotesReqd='0' EmpType='S'/>      <z:row WorkType='6505' WorkDescription='Site Subbies - Estimating' NotesReqd='0' EmpType='S'/>      <z:row WorkType='3810' WorkDescription='Factory Subbie - Material Preperation' NotesReqd='0' EmpType='S'/>      <z:row WorkType='3820' WorkDescription='Factory Subbie - Edge Banding' NotesReqd='0' EmpType='S'/>      <z:row WorkType='4810' WorkDescription='Factory Subbie - Building' NotesReqd='0' EmpType='S'/>      <z:row WorkType='4820' WorkDescription='Factory Subbie - Cleaning Projects' NotesReqd='0' EmpType='S'/>      <z:row WorkType='4830' WorkDescription='Factory Subbie - Wrapping Projects' NotesReqd='0' EmpType='S'/>      <z:row WorkType='4850' WorkDescription='Factory Subbie - Pickups and Deliveries' NotesReqd='0' EmpType='S'/>      <z:row WorkType='4860' WorkDescription='Factory Subbie - Loading' NotesReqd='0' EmpType='S'/>      <z:row WorkType='5810' WorkDescription='Factory Subbie - Sanding' NotesReqd='0' EmpType='S'/>      <z:row WorkType='5820' WorkDescription='Factory Subbie - Booth Load/Unload' NotesReqd='0' EmpType='S'/>      <z:row WorkType='5830' WorkDescription='Factory Subbie - Painting - Wrapping' NotesReqd='0' EmpType='S'/>      <z:row WorkType='4870' WorkDescription='Factory Subbie - Cleaning Up Project' NotesReqd='0' EmpType='S'/>      <z:row WorkType='7820' WorkDescription='Factory Subbie - Maintenance - Machines Cleaning Program' NotesReqd='0'           EmpType='S'/>      <z:row WorkType='7820' WorkDescription='Factory Subbie - Maintenance - Machines Maintenance and Repairs' NotesReqd='1'           EmpType='S'/>      <z:row WorkType='7840' WorkDescription='Factory Subbie - Maintenance - Factory Cleaning Program' NotesReqd='0'           EmpType='S'/>      <z:row WorkType='7850' WorkDescription='Factory Subbie - Maintenance - Factory Maintenance and Repairs' NotesReqd='1'           EmpType='S'/>      <z:row WorkType='7810' WorkDescription='Factory Subbie - Maintenance - Factory Stock Take' NotesReqd='1' EmpType='S'/>      <z:row WorkType='7860' WorkDescription='Factory Subbie - Maintenance - Painting Cleaning Program' NotesReqd='0'           EmpType='S'/>      <z:row WorkType='7870' WorkDescription='Factory Subbie - Maintenance - Painting Maintenance and Repairs' NotesReqd='1'           EmpType='S'/>      <z:row WorkType='7880' WorkDescription='Factory Subbie - WHS' NotesReqd='0' EmpType='S'/>      <z:row WorkType='6540' WorkDescription='Site Subbies - Installation' NotesReqd='0' EmpType='S'/>  </rs:data>  </xml>    

I need to be able to read selected fields out of this into a simple XML Document similar to this.

  <?xml version="1.0" ?>    <complete>       <option value="1">one</option>       <option value="2">two</option>       <option value="3">three</option>       <option value="4">four</option>       <option value="5">five</option>       <option value="6">six</option>       <option value="7">seven</option>       <option value="8">eight</option>       <option value="9">nine</option>       <option value="10">ten</option>    </complete>    

Where the Value will be the WorkType Field from the Original XML Document and the Name will be the WorkType + the Work Description.

This is for use in the DHTMLX Combobox which cannot read the advanced Dataset.

No comments:

Post a Comment