)を検索すると、第1レベルの子供をXML文書で検索することをどのように制限できますか?例えばjQuery:第1レベルの子供のみを検索する(
:
はオネのWebサービス(https://services.onetcenter.org/developer/)
<?xml version="1.0" encoding="UTF-8"?>
<report code="27-2011.00">
<career>
<code>13-2011.01</code>
<title>Accountants</title>
<tags bright_outlook="true" green="false" apprenticeship="false"/>
<also_called>
<title>Accountant</title>
<title>Accounting Manager</title>
<title>Certified Public Accountant (CPA)</title>
<title>Staff Accountant</title>
</also_called>
<what_they_do>Analyze financial information and prepare financial reports to determine or maintain record of assets, liabilities, profit and loss, tax liability, or other financial activities within an organization.</what_they_do>
<on_the_job>
<task>Prepare, examine, or analyze accounting records, financial statements, or other financial reports to assess accuracy, completeness, and conformance to reporting and procedural standards.</task>
<task>Report to management regarding the finances of establishment.</task>
<task>Establish tables of accounts and assign entries to proper accounts.</task>
</on_the_job>
<resources>
<resource href="https://services.onetcenter.org/ws/mnm/careers/13-2011.01/knowledge">
<title>Knowledge</title>
</resource>
..........................
..........................
.............................
</explore_more>
<where_do_they_work>
<industry href="https://services.onetcenter.org/ws/mnm/browse/54" percent_employed="33">
<code>54</code>
<title>Professional, Science, & Technical</title>
</industry>
</where_do_they_work>
</report>
ここ
からの応答であるこのXMLを考えてみましょう私は、モーダルダイアログでこのデータをレイアウトしようとしています。だから、私はそれぞれのノードを扱う必要があります。
だからまずタイトルを探す必要があります。だから、私はこのコードを試しました。
var career = $(xml).find('career');
その後、私は
ヘッダフィールドにタイトルタグのテキストコンテンツを割り当てるそしてこうして私は
$('#myh4').html($(career).find('title').text());
を使用してコード化された。しかし、明らかに、それはすべてのタイトルタグににテキストを割り当てヘッダ。
したがって、単に検索機能を第1レベルの子供のみに制限することができます。次のレベルに掘ってからそれを防ぐ方法を意味のような子どもたちが使う.children('title').text()
instead