通过链接[https://www.ncbi.nlm.nih.gov/gene/7128?report=xml&format=text][1]我检索了一种XML格式。从这种格式我检索了Gene-commentary_headings之间的所有信息。因此我使用了DOMDocuments和getElemenetsByTagName。现在,我正在尝试检索这条线;例如,名称为GeneOntology。 GeneOntology位于Gene-commmentary_heading的22标签上。我只检索位于Gene-commentary_headings部分内的信息。
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.hrh.crosswalk" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MICROPHONE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>
现在,我正在尝试打印所有名称为Other-source_anchor的标签。例如
InAppBrowser.open("https://appr.tc/r/123", "_blank", "location=no")
但是在GOA上也有相同的标签但是更高级别。我只想在DNA结合水平检索标签。如果我使用
<Gene-commentary_heading>GeneOntology</Gene-commentary_heading>.
我没有结果。如果我用$ doc更改$ node,我会检索带有标记的所有nodeValues。如何确保我只检索DNA绑定级别的Other-source_anchor标记的nodeValues?
贝娄是我写的代码:
<Other-source_anchor>DNA binding</Other-source_anchor>
我在上面的代码中使用的部分xml文件。
foreach($node->getElementsByTagName('Other-source_anchor') as $subnode)
答案 0 :(得分:0)
以字符串格式检索给定路径的信息的函数
function xml_retriever($xml_link,$path){
$result = file_get_contents($xml_link);
$xml = simplexml_load_string($result);
$doc = new DOMDocument();
$doc = DOMDocument::loadXML($xml);
$xpath = new DOMXPath($doc);
$entries = $xpath->query($path);
$attr = '';
foreach($entries as $node){
$attr .= '|'.' '.$node->nodeValue. "\r\n";
$attr = ltrim($attr, '|');
}
return $attr;
}
如果函数有效,可以进行简单测试
# Example query and example path
$esearch_test = "https://www.ncbi.nlm.nih.gov/gene/7128?report=xml&format=text";
$query = "/Entrezgene/Entrezgene_properties/Gene-commentary[3]/Gene-commentary_comment/Gene-commentary[1]/Gene-commentary_comment/Gene-commentary[*]/Gene-commentary_source/Other-source/Other-source_anchor";
# Print the result
echo xml_retriever($esearch_test,$query);