<?php
class
Atom {
var
$name
;
var
$symbol
;
var
$atomic_no
;
function
__construct(
$aa
) {
foreach
(
$aa
as
$k
=>
$v
)
$this
->
$k
=
$aa
[
$k
];
}
}
function
read_data(
$filename
) {
$xml_data
= implode(
""
, file(
$filename
));
$xml_parser
= xml_parser_create();
xml_parser_set_option(
$xml_parser
, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option(
$xml_parser
, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct(
$xml_parser
,
$xml_data
,
$values
,
$tags
);
xml_parser_free(
$xml_parser
);
foreach
(
$tags
as
$key
=>
$val
) {
if
(
$key
==
"atom"
) {
$atom_ranges
=
$val
;
for
(
$i
= 0;
$i
<
count
(
$atom_ranges
);
$i
+= 2) {
$offset
=
$atom_ranges
[
$i
] + 1;
$len
=
$atom_ranges
[
$i
+ 1] -
$offset
;
$tdb
[] = parseAtoms(
array_slice
(
$values
,
$offset
,
$len
));
}
}
else
{
continue
;
}
}
return
$tdb
;
}
function
parseAtoms(
$mvalues
) {
for
(
$i
= 0;
$i
<
count
(
$mvalues
);
$i
++) {
$ato
[
$mvalues
[
$i
][
"tag"
]] =
$mvalues
[
$i
][
"value"
];
}
return
new
Atom(
$ato
);
}
$db
= read_data(
"atoms.xml"
);
echo
"Database of atoms objects:\n"
;
print_r(
$db
);
?>