[英]DOMElement::setAttribute not working php
I've an xml file containing tag like this. 我有一个包含这样的标签的xml文件。
<server>
<conversation ip="12.0.0.1" email="none">
<chat userstatus="1" adminstatus="2" username="admin">muja</chat>
</conversation>
</server>
Now I want to update the email attribute of the conversation tag. 现在,我想更新对话标签的电子邮件属性。 When I use
$conv->getAttribute("email")
it echo's me the correct result ie none.But if I try to set it using $conv->setAttribute("email","abc")
it does not update the value. 当我使用
$conv->getAttribute("email")
它回显是正确的结果,即没有。但是,如果我尝试使用$conv->setAttribute("email","abc")
,则不会更新该值。 Here's what I am doing. 这就是我在做什么。
This is the GetClientConversation(): 这是GetClientConversation():
private function GetClientConversation()
{
foreach($this->conversation as $convTag)
{
if($convTag->getAttribute("ip") == $this->clientip)
{
return $convTag;
}
}
return "noConversation";
}
This function returns me the correct conversationTag that I needed. 此函数返回我所需的正确的sessionTag。
And i get these conversationsTags array using 我使用这些对话标签
$this->conversation=$this->xmlDom->getElementsByTagName("conversation");
Edit: 编辑:
public function GetConversation()
{
$conv=$this->GetClientConversation();
if($conv!="noConversation")
{
if($conv->getAttribute("email")=="none")
{
$conv->setAttribute("email","abc"); // -- Here
return json_encode($this->RetrieveConversation($conv));
}
else if($conv->getAttribute("email")==$this->adminEmail)
{
return json_encode($this->RetrieveConversation($conv));
}
else
{
return "Admin Already Chatting";
}
}
else
{
$this->CreateNewConversation();
return "no";
}
}
This is the code from where I am trying to set the attribute. 这是我尝试设置属性的代码。
You have correctly used setAttribute()
. 您已经正确使用了
setAttribute()
。
You are retrieving your XML and passing the string back to json_encode()
. 您正在检索XML,并将字符串传递回
json_encode()
。 However, if the RetrieveConversation()
method has not correctly called saveXML()
prior to returning the string, your modifications will not be available in the output XML string. 但是,如果
RetrieveConversation()
方法在返回字符串之前未正确调用saveXML()
,则您的修改将在输出XML字符串中不可用。 Be sure you have called saveXML()
. 确保已调用
saveXML()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.