I've reformatted your XML for readability (the content is unmodified). It looks like you only posted a part of your XML in your question, since you're missing a few closing </lst> tags at the end and you're missing a closing </response> as well:
$xml = '
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">10</int>
<lst name="params">
<str name="q">*:*</str>
<str name="facet.field">main</str>
<str name="facet.mincount">1</str>
<str name="rows">0</str>
<str name="facet">on</str>
</lst>
</lst>
<result name="response" numFound="5473" start="0"/>
<lst name="facet_counts">
<lst name="facet_queries"/>
<lst name="facet_fields">
<lst name="main">
<int name="Victoria University Photograph Collection">1693</int>
</lst>' /* added by me */ . '
</lst>' /* added by me */ . '
</lst>' /* added by me */ . '
</response>' /* added by me */ . '
';
$input = simplexml_load_string($xml);
SimpleXML will return a reference to the root element, in your case <response>. As you can see, in your example code this <response> element contains two <lst> children and one <result> child. This means $input->lst will be an array containing two entries: the two <lst> elements in the order in which they appear in your document.
Your code is specifically looking for <int> elements as a first child of something, which only appears to be the case for the first <lst> element. There's another one in the second <lst> element, but that one's hidden away at a depper level so I'll skip it for now. So basically, we need to look for <int>s in $input->lst[0].
$arr = array();
foreach ($input->lst[0]->int as $int) {
// get the name from the attributes
$name = (string)$int['name'];
// get the element's text content
$value = (string)$int;
$arr[$name] = $value;
}
print_r($arr);
If you want to search through all (top-level) <lst> you will need an extra loop:
$arr = array();
foreach ($input->lst as $lst) {
foreach ($lst->int as $int) {
$name = (string)$int['name'];
$value = (string)$int;
$arr[$name] = $value;
}
}
print_r($arr);
With your example code, both cases output the following array (since the <int> in the second <lst> is buried a little deeper):
Array
(
[status] => 0
[QTime] => 10
)
Now, if you want to look through any nested <lst> no matter how deep, you might want to consider making a recursive function out of it:
function parseLst($lst, &$arr) {
// note the & before $arr, this is necessary to make `$arr[$name] = $value;` work.
// Another option would be to use `global $arr;` and not pass it as an argument,
// or if you're doing this in a class, to use `$this->arr` instead.
foreach ($lst->int as $int) {
$name = (string)$int['name'];
$value = (string)$int;
$arr[$name] = $value;
}
foreach ($lst->lst as $childLst) {
parseLst($childLst, $arr);
}
};
$arr = array();
foreach ($input->lst as $lst) {
parseLst($lst, $arr);
}
print_r($arr);
This will yield:
Array
(
[status] => 0
[QTime] => 10
[Victoria University Photograph Collection] => 1693
)
$input? Can you add that code to your question?