我正在尝试使用 PHP 读取此 XML 文件,并且我有两个根元素。我用 PHP 编写的代码仅读取一个根元素,当我添加另一个根元素 ( <action>) 时,它会出现错误。我想做这样的事情:if($xml->action=="register")然后打印所有参数。
这是我的 XML 文件:
<?xml version='1.0' encoding='ISO-8859-1'?>
<action>register</action>
<paramters>
<name>Johnny B</name>
<username>John</username>
</paramters>
Run Code Online (Sandbox Code Playgroud)
这是我的 PHP 脚本:
<?php
$xml = simplexml_load_file("test.xml");
echo $xml->getName() . "<br />";
foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br />";
}
?>
Run Code Online (Sandbox Code Playgroud)
我真的不知道该怎么做这一切......
我正在使用apacheservicemix,我尝试使用apache camel验证xml文档.我有这条名为students_route.xml的路线:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="file:project/students.xml"/>
<doTry>
<to uri="validator:file:project/students.xsd"/>
<to uri="file:valid"/>
<doCatch>
<exception>org.apache.camel.ValidationException</exception>
<to uri="file:invalid"/>
</doCatch>
<doFinally>
<to uri="file:finally"/>
</doFinally>
</doTry>
</route>
</camelContext>
</blueprint>
Run Code Online (Sandbox Code Playgroud)
我创建了3个目录:valid,invalid和finally.我在karaf"start students_route.xml"中运行后没有任何反应.当我查看日志时,我得到的错误只是这样的一些消息:"路由:route2已启动并消耗:Endpoint [file://project/students.xml]".我想象一个文件应该在有效/无效的情况下创建目录xml文件是否有效.
我是这些技术的新手,我不知道如何使这项工作.我将衷心感谢您的帮助.先感谢您!
嘿,我正在尝试验证我的xml文件中的用户名和密码是否与我的数据库中的用户名和密码相同,但mysql_num_rows为零.所以我的SELECT查询一定有问题.这是我的代码:
public function verifyDB()
{
//connection to database
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('proiect_is') or die(mysql_error());
$data =mysql_query("SELECT id FROM users WHERE userName ='$this->xml->parameters->username' AND password ='$this->xml->parameters->pass'");
//we check if any row was returned
echo $data;
echo $this->xml->parameters->username."<BR>";
echo $this->xml->parameters->pass."<BR>";
print_r(mysql_num_rows($data));
if (mysql_num_rows($data))
{
$row = mysql_fetch_assoc($data);
$this->_id= $row['id'];
echo $row;
return true;
}
else
{return false;}
}
Run Code Online (Sandbox Code Playgroud)
这是我的xml登录文件:
<xml version="">
<action>log_in</action>
<parameters>
<username>Ionel P</username>
<pass>abdef01</pass>
</parameters>
</xml>
Run Code Online (Sandbox Code Playgroud) xml ×3
php ×2
apache-camel ×1
apache-karaf ×1
parsing ×1
root ×1
select ×1
validation ×1
xsd ×1