PHP simplexml_加载_文件相同属性
我有一个xml文件: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> <
<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];
}