Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP simplexml_加载_文件相同属性_Php_Xml - Fatal编程技术网

PHP simplexml_加载_文件相同属性

PHP simplexml_加载_文件相同属性,php,xml,Php,Xml,我有一个xml文件: <RecNo_1> <Field Name="erfdat">19.11.1999</Field> <Field Name="erfuser">user1</Field> <Field Name="l_dat">18.12.2014</Field> <Field Name="l_user">deluser1</Field> </RecNo_1> <

我有一个xml文件:

<RecNo_1>
<Field Name="erfdat">19.11.1999</Field>
<Field Name="erfuser">user1</Field>
<Field Name="l_dat">18.12.2014</Field>
<Field Name="l_user">deluser1</Field>
</RecNo_1>

<RecNo_2>
<Field Name="erfdat">22.11.1999</Field>
<Field Name="erfuser">user2</Field>
<Field Name="l_dat">18.12.2015</Field>
<Field Name="l_user">deluser2</Field>
</RecNo_2>
我认为这应该是RecNo_1“19.11.1999”和RecNo_2“22.11.1999”的输出。但它什么也不输出。。。我如何简单地获得这些值

$xml = '<root>
<RecNo_1>
<Field Name="erfdat">19.11.1999</Field>
<Field Name="erfuser">user1</Field>
<Field Name="l_dat">18.12.2014</Field>
<Field Name="l_user">deluser1</Field>
</RecNo_1>
<RecNo_2>
<Field Name="erfdat">22.11.1999</Field>
<Field Name="erfuser">user2</Field>
<Field Name="l_dat">18.12.2015</Field>
<Field Name="l_user">deluser2</Field>
</RecNo_2>
</root>';

$xml = simplexml_load_string($xml);

$result = $xml->xpath('RecNo_1/Field'); 

while(list(,$node) = each($result)) {
  if("erfdat"==(string)$node['Name']){
   print $node;#shows once 19.11.1999
  }
}

祝您愉快。

这应该会有所帮助-非常感谢!这正是我需要的!
$xml = '<root>
<RecNo_1>
<Field Name="erfdat">19.11.1999</Field>
<Field Name="erfuser">user1</Field>
<Field Name="l_dat">18.12.2014</Field>
<Field Name="l_user">deluser1</Field>
</RecNo_1>
<RecNo_2>
<Field Name="erfdat">22.11.1999</Field>
<Field Name="erfuser">user2</Field>
<Field Name="l_dat">18.12.2015</Field>
<Field Name="l_user">deluser2</Field>
</RecNo_2>
</root>';

$xml = simplexml_load_string($xml);

$result = $xml->xpath('RecNo_1/Field'); 

while(list(,$node) = each($result)) {
  if("erfdat"==(string)$node['Name']){
   print $node;#shows once 19.11.1999
  }
}
$xml = simplexml_load_string($xml);
for($i=1;$i<=2;$i++){
   $result = $xml->xpath("RecNo_{$i}/Field[@Name='erfdat']"); 
   print (string)$result[0];
}