PHP SimpleXML로 구문 분석하는 XML이 있습니다. 내 XML 파일의 일부는 다음과 같습니다XML로 PHP 구문 분석 - SimpleXML
Parsing 'deviceStatusPolling'...
Has 1 attribute(s):
- interval: 60
그것은 아이들을 구문 분석하지 않습니다 :
<r: datapoint programmaticName="t_val_sys_pct_mssDbPartitionUsage" />
이이
<deviceStatusPolling interval="60">
<r:datapoint programmaticName="t_val_sys_pct_mssDbPartitionUsage" />
</deviceStatusPolling>
내가 그 구문 분석 내가 무엇을 얻을 구문 분석 함수 :
function parse_recursive(SimpleXMLElement $element, $level = 0) {
$indent = str_repeat("\t", $level); // determine how much we'll indent
$value = trim((string) $element); // get the value and trim any whitespace from the start and end
$attributes = $element->attributes(); // get all attributes
$children = $element->children(); // get all children
echo "{$indent}Parsing '{$element->getName()}'...<br>";
if(count($children) == 0 && !empty($value)) // only show value if there is any and if there aren't any children
{
echo "{$indent}Value: {$element}<br>";
}
// only show attributes if there are any
if(count($attributes) > 0)
{
echo $indent.'Has '.count($attributes).' attribute(s):<br>';
foreach($attributes as $attribute)
{
echo "{$indent}- {$attribute->getName()}: {$attribute}<br>";
}
}
// only show children if there are any
if(count($children))
{
echo $indent.'Has '.count($children).' child(ren):<br>';
foreach($children as $child)
{
parse_recursive($child, $level+1); // recursion :)
}
}
echo $indent; // just to make it "cleaner"
echo "<br>";
}
SimpleXML의 한계점이 있습니까? 아니면 내가 잘못하고있는거야?
감사
SO! 우리에게 당신의 코드를 보여주십시오. – nickhar
도 인쇄 할 때 어떤 점이 좋을지 알려주세요. – Serge
인쇄하기 위해 무엇을하고 있는지 여전히 볼 수 없습니다 - 어떤 코드입니까? 인쇄? – nickhar