Re: [PHP] How can I load this XML file into an array? (and. . . how do I reference the values?)

2007-10-26 Thread mike
On 10/26/07, John A DAVIS [EMAIL PROTECTED] wrote:


 I've found simple examples on the web that work a simple XML file (song,
 title, etc) but I need one that will parse an XML file into elements of an
 array. And then, I need to reference these elements to validate against a
 database. The data has to do with drinking water lab samples:

use simplexml (php.net/simplexml)

you may need to do string replacement though, replacing EN: with
EN_ or something; having : has proven to be complex for me in the
past.

$xml = file_get_contents('file.xml');
$xml = str_replace('EN:', 'EN_', $xml);
$sxml = simplexml_load_string($xml);
var_dump($sxml);

that should be enough to get you started... enjoy!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How can I load this XML file into an array? (and. . . how do I reference the values?)

2007-10-26 Thread John A DAVIS


this works:
$xml_data = file('xml_edwr2.xml');var_dump($xml_data);

I can get the var_dump to work for 1 sample, but I guess there are a many samples in one xml file which turns into something like this(so, there is no way for me to reference a "column"):

array(9780) { [0]= string(19) " " [1]= string(23) " " [2]= string(35) " " [3]= string(38) " " [4]= string(89) " 10943 " [5]= string(95) " STATE " [6]= string(39) " " [7]= string(36) " " [8]= string(24) " " [9]= string(42) " " [10]= string(78) " CCHD " [11]= string(82) " 01316-TC/ECZ " [12]= string(67) " NY0930054 " [13]= string(86) " DISTRIBUTION " [14]= string(62) " TC " [15]= string(82) " SP " [16]= string(83) " FSD " [17]= string(83) " N " [18]= string(83) " N " [19]= string(41) " " [20]= string(84) " MATT DOYLE " [21]= string(42) " " [22]= string(88) " 2006-02-06 " [23]= string(86) " 12:00:00 " [24]= string(38) " " [25]= string(71) " 100 " [26]= string(91) " 3 " [27]= string(39) " " [28]= string(48) " " [29]= string(71) " 0.2 " [30]= string(91) " 1 " [31]= string(116) " FreeChlorineResidual " [32]= string(49) " " [33]= string(48) " " [34]= string(71) " 0.2 " [35]= string(91) " 1 " [36]= string(117) " TotalChlorineResidual " [37]= string(49) " " [38]= string(48) " " [39]= string(70) " 72 " [40]= string(67) " F " [41]= string(91) " 2 " [42]= string(112) " WaterTemperature " [43]= string(49) " " [44]= string(48) " " [45]= string(69) " 2 " [46]= string(91) " 1 " [47]= string(105) " Turbidity " [48]= string(49) " " [49]= string(48) " " [50]= string(69) " 4 " [51]= string(91) " 1 " [52]= string(98) " PH " [53]= string(49) " " [54]= string(48) " " [55]= string(71) " 200 " [56]= string(91) " 3 " [57]= string(104) " FlowRate " [58]= string(49) " " [59]= string(40) " " [60]= string(60) " 2/9/2006 " [61]= string(41) " " [62]= string(80) " TC " [63]= string(43) " " [64]= string(50) " " [65]= string(87) " RR SINK " [66]= string(70) " DS " [67]= string(51) " " [68]= string(25) " " [69]= string(24) " " [70]= string(42) " " [71]= string(78) " CCHD " [72]= string(82) " 01370-TC/ECZ " [73]= string(67) " NY0930094 " [74]= string(86) " DISTRIBUTION " [75]= string(62) " TC " [76]= string(82) " SP " [77]= string(83) " N " [78]= string(83) " N " [79]= string(41) " " [80]= string(85) " LIZ TEDFORD " [81]= string(42) " " [82]= string(88) " 2006-02-07 " [83]= string(84) " BP " [84]= string(38) " " [85]= string(71) " 100 " [86]= string(91) " 3 " [87]= string(39) " " [88]= string(40) " " [89]= string(60) " 2/9/2006 " [90]= string(41) " " [91]= string(80) " TC " [92]= string(43) " " [93]= string(50) " " [94]= string(90) " COFFEE BAR " [95]= string(70) " DS " [96]= string(51) " " [97]= string(25) " " [98]= string(24) " " [99]= string(42) " " [100]= string(82) " 01596-TC/ECZ " [101]= string(67) " NY0922914 " [102]= string(77) " 137 " [103]= string(62) " TC " [104]= string(82) " RT " [105]= string(83) " Y " [106]= string(83) " N " [107]= string(41) " " [108]= string(76) " SB " [109]= string(42) " " [110]= string(88) " 2006-02-13 " [111]= string(38) " " [112]= string(71) " 100 " [113]= string(91) " 3 " [114]= string(39) " " [115]= string(40) " " [116]= string(61) " 2/21/2006 " [117]= string(41) " " [118]= string(80) " TC " [119]= string(43) " " [120]= string(50) " " [121]= string(89) " LOT 1 CWT " [122]= string(70) " DS " [123]= string(51) " " [124]= string(25) " " [125]= string(24) " " [126]= string(42) " " [127]= string(78) " CCHD " [128]= string(82) " 01604-TC/ECZ " [129]= string(67) " NY0900220 " [130]= string(77) " 140 " [131]= string(62) " TC " [132]= string(82) " SP " [133]= string(83) " N " [134]= string(83) " N " [135]= string(41) " " [136]= string(87) " TIM SIMONETTE " [137]= string(42) " " [138]= string(88) " 2006-02-13 " [139]= string(38) " " [140]= string(71) " 100 " [141]= string(91) " 3 " [142]= string(39) " " [143]= string(48) " " [144]= string(71) " 0.4 " [145]= string(91) " 1 " [146]= string(116) " FreeChlorineResidual " [147]= string(49) " " [148]= string(40) " " [149]= string(61) " 2/15/2006 " [150]= string(41) " " [151]= string(80) " TC " [152]= string(43) " " [153]= string(50) " " [154]= string(90) " 24 RAND HL " [155]= string(70) " DS " [156]= string(51) " " [157]= string(25) " " [158]= string(24) " " [159]= string(42) " " [160]= string(78) " CCHD " [161]= string(82) " 01664-TC/ECZ " [162]= string(67) " NY0922471 " [163]= string(79) " 52848 " [164]= string(62) " TC " [165]= string(82) " SP " [166]= string(83) " N " [167]= string(83) " N " [168]= string(41) " " [169]= string(84) " MATT DOYLE " [170]= string(42) " " [171]= string(88) " 2006-02-14 " [172]= string(38) " " [173]= string(71) " 100 " [174]= string(91) " 3 " [175]= string(39) " " [176]= string(48) " " [177]= string(71) " 0.4 " [178]= string(91) " 1 " [179]= string(116) " FreeChlorineResidual " [180]= string(49) " " [181]= string(40) " " [182]= string(61) " 2/16/2006 " [183]= string(41) " " [184]= string(80) " TC " [185]= string(43) " " [186]= string(50) " " [187]= string(85) " LOT 9 " [188]= 

Re: [PHP] How can I load this XML file into an array? (and. . . how do I reference the values?)

2007-10-26 Thread mike
On 10/26/07, John A DAVIS [EMAIL PROTECTED] wrote:


 this works:
 $xml_data = file('xml_edwr2.xml');
 var_dump($xml_data);

 I can get the var_dump to work for 1 sample, but I guess there are a many
 samples in one xml file which turns into something like this(so, there is no
 way for me to reference a column):


the code came out horribly in email, but you should be able to use
xpath-y type stuff to access it.

i.e.

foreach($sxml-node-childnode as $node) {
  now you are in a foreach loop on this level
}

simplexml is great for quick parsing of well-formed XML.

there's also DOM functions, PEAR libraries, and of course XSLT to try
to get the XML into an easier to use format... but I typically try to
use built in stuff when possible :)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How can I load this XML file into an array? (and. . . how do I reference the values?)

2007-10-26 Thread mike
On 10/26/07, John A DAVIS [EMAIL PROTECTED] wrote:


 simplexml won't work for our version of PHP. planning on upgrading once we
 get the new server

then i guess if you need it now, it's probably easiest to look for a
PEAR module.

however... gophp5.org! :)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How can I load this XML file into an array? (and. . . how do I reference the values?)

2007-10-26 Thread John A DAVIS


simplexml won't work for our version of PHP. planning on upgrading once we get the new server

 "mike" [EMAIL PROTECTED] 10/26/2007 4:42:09 PM 
On 10/26/07, John A DAVIS [EMAIL PROTECTED] wrote: this works: $xml_data = file('xml_edwr2.xml'); var_dump($xml_data); I can get the var_dump to work for 1 sample, but I guess there are a many samples in one xml file which turns into something like this(so, there is no way for me to reference a "column"):the code came out horribly in email, but you should be able to usexpath-y type stuff to access it.i.e.foreach($sxml-node-childnode as $node) { now you are in a foreach loop on this level}simplexml is great for quick parsing of well-formed XML.there's also DOM functions, PEAR libraries, and of course XSLT to tryto get the XML into an easier to use format... but I typically try touse built in stuff when possible :)