私は単純なopencalaisプロジェクトに取り組んでいます。子どもがカウントするカテゴリを動的に実現するために私のプログラムが必要でした。simpleXMLでchildren()を実際に理解できない
私は、例のように発生した場合、子孫を処理する別の関数を記述しようとしていました。 (複数の企業/人/など)が、このコードはすべての世話をしたようです。それは私にいくつかのwork.Butを保存して以来、本当に良いことですが、私はPHPに新しいと私は子供のドキュメントを読んだが、カントはこれがどうなったのか理解しています。
コード:
$xml = simplexml_load_string("$response");
print_fr($xml);
$categories = $xml->CalaisSimpleOutputFormat->children();
print_fr($categories);
foreach($categories as $entities) {
$eName = $entities->getName();
if($eName!== "Topics") {
echo "<br /> The Entity is -- \" ".$eName."\"";
echo "<br /> The Entity Name is -- \" ".$entities."\"";
echo "<br /> The Relevance Score is -- \" ".$entities['relevance']."\"";
}
else if($eName == "Topics") {
echo "Deal with topics later";
}
}
O/P:何が起こっているのか、あなたのxmlファイルで
SimpleXMLElement Object
(
[Description] => SimpleXMLElement Object
(
[allowDistribution] => false
[allowSearch] => false
[calaisRequestID] => a647072b-203c-cbb0-1319-045ba23774d2
[externalID] => SimpleXMLElement Object
(
[0] =>
)
[id] => http://id.opencalais.com/ZwD-c-aYZMsFWaSXn2vWbw
[about] => http://d.opencalais.com/dochash-1/e12aabaf-1b01-3844-96bc-90238dae24dc
[docTitle] => SimpleXMLElement Object
(
)
[docDate] => 2007-09-15
[externalMetadata] => SimpleXMLElement Object
(
)
[submitter] => Calais REST Sample
)
[CalaisSimpleOutputFormat] => SimpleXMLElement Object
(
[Company] => Array
(
[0] => Tensleep Corporation
[1] => International Star Inc.
[2] => XSTV Media Inc.
[3] => XSTV Corporation
[4] => Gerard Klauer Mattison
[5] => IDC
)
[Event] => Array
(
[0] => General or Shareholder Meeting
[1] => M&A
)
[Position] => analyst
[City] => Shreveport
[Facility] => The Hilton Hotel
[Person] => Array
(
[0] => David Bailey
[1] => Roger Kay
)
[Topics] => SimpleXMLElement Object
(
[Topic] => Business_Finance
)
)
)
SimpleXMLElement Object
(
[Company] => Array
(
[0] => Tensleep Corporation
[1] => International Star Inc.
[2] => XSTV Media Inc.
[3] => XSTV Corporation
[4] => Gerard Klauer Mattison
[5] => IDC
)
[Event] => Array
(
[0] => General or Shareholder Meeting
[1] => M&A
)
[Position] => analyst
[City] => Shreveport
[Facility] => The Hilton Hotel
[Person] => Array
(
[0] => David Bailey
[1] => Roger Kay
)
[Topics] => SimpleXMLElement Object
(
[Topic] => Business_Finance
)
)
The Entity is -- " Company"
The Entity Name is -- " Tensleep Corporation"
The Relevance Score is -- " 0.451"
The Entity is -- " Company"
The Entity Name is -- " International Star Inc."
The Relevance Score is -- " 0.142"
The Entity is -- " Company"
The Entity Name is -- " XSTV Media Inc."
The Relevance Score is -- " 0.364"
The Entity is -- " Event"
The Entity Name is -- " General or Shareholder Meeting"
The Relevance Score is -- " "
The Entity is -- " Position"
The Entity Name is -- " analyst"
The Relevance Score is -- " 0.334"
The Entity is -- " City"
The Entity Name is -- " Shreveport"
The Relevance Score is -- " 0.112"
The Entity is -- " Company"
The Entity Name is -- " XSTV Corporation"
The Relevance Score is -- " 0.319"
The Entity is -- " Company"
The Entity Name is -- " Gerard Klauer Mattison"
The Relevance Score is -- " 0.247"
The Entity is -- " Company"
The Entity Name is -- " IDC"
The Relevance Score is -- " 0.169"
The Entity is -- " Event"
The Entity Name is -- " M&A"
The Relevance Score is -- " "
The Entity is -- " Facility"
The Entity Name is -- " The Hilton Hotel"
The Relevance Score is -- " 0.112"
The Entity is -- " Person"
The Entity Name is -- " David Bailey"
The Relevance Score is -- " 0.247"
The Entity is -- " Person"
The Entity Name is -- " Roger Kay"
The Relevance Score is -- " 0.169"
Deal with topics later
に ' "$応答が"'です新しい文字列を作成し、$ responseをそれに貼り付け、その新しい文字列を関数に渡します。引用符はまったく必要ありません。 –
こんにちはマーク、私のPHPの経験は今のところ私は安全であった数日のうちです。入力いただきありがとうございます。 – wtflux
誰も本当に子供を理解していません。それが人生。 –