Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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
如何使用lua中的字符串find提取xml元素值_Xml_String_Lua_Match_Element - Fatal编程技术网

如何使用lua中的字符串find提取xml元素值

如何使用lua中的字符串find提取xml元素值,xml,string,lua,match,element,Xml,String,Lua,Match,Element,我需要使用lua从soap信封中的soap头中提取Username、Password元素值 样本要求- ... <soap:Header><wsse:Security xmlns:wsse=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd” soapenv:mustUnderstand=“1”> <wsse:UsernameToken><w

我需要使用lua从soap信封中的soap头中提取Username、Password元素值

样本要求-

...
<soap:Header><wsse:Security xmlns:wsse=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd” soapenv:mustUnderstand=“1”>
<wsse:UsernameToken><wsse:Username>testuser</wsse:Username>
<wsse:Password wsse:Type=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText”>testpassword</wsse:Password>
</wsse:UsernameToken></wsse:Security></soap:Header>
...

。。。
测试用户
测试密码
...
使用following并不能给出正确的结果(不能使用xml解析器),有没有更好的方法来对其进行模式化

local username = string.match(soapload, "^.+Username>(.+)</wsse:Username>.+$")
local password = string.match(soapload, "^.+PasswordText\">(.+)</wsse:Password>.+$")
localusername=string.match(soapload,“^.+username>(.+).+$”)
本地密码=string.match(soapload,“^.+PasswordText\”>(.+).+$”)
您的示例使用了“右双引号”(
PasswordText“>
)code\u201D,因此您没有得到任何东西。而且它们不需要转义,这是不必要的

local soapload = [[
<soap:Header><wsse:Security xmlns:wsse=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd” soapenv:mustUnderstand=“1”>
<wsse:UsernameToken><wsse:Username>testuser</wsse:Username>
<wsse:Password wsse:Type=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText”>testpassword</wsse:Password>
</wsse:UsernameToken></wsse:Security></soap:Header>
]]

local username = string.match(soapload, "<wsse:Username>(.-)</wsse:Username>")
local password = string.match(soapload, "PasswordText”>(.-)</wsse:Password>")

print(username)
print(password)
localsoapload=[[
测试用户
测试密码
]]
本地用户名=string.match(soapload,(.-)“”)
本地密码=string.match(soapload,“PasswordText”>(.-))
打印(用户名)
打印(密码)
您的示例使用了“右双引号”(
PasswordText“>
)code\u201D,因此您没有得到任何东西。而且它们不需要转义,这是不必要的

local soapload = [[
<soap:Header><wsse:Security xmlns:wsse=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd” soapenv:mustUnderstand=“1”>
<wsse:UsernameToken><wsse:Username>testuser</wsse:Username>
<wsse:Password wsse:Type=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText”>testpassword</wsse:Password>
</wsse:UsernameToken></wsse:Security></soap:Header>
]]

local username = string.match(soapload, "<wsse:Username>(.-)</wsse:Username>")
local password = string.match(soapload, "PasswordText”>(.-)</wsse:Password>")

print(username)
print(password)
localsoapload=[[
测试用户
测试密码
]]
本地用户名=string.match(soapload,(.-)“”)
本地密码=string.match(soapload,“PasswordText”>(.-))
打印(用户名)
打印(密码)

由于某些原因,我得到了两个零,将再次检查。可能是尝试此模式
“PasswordText.-”
谢谢Mike。通过soap ui发送此信息时,我有一些奇怪的行为,邮递员工作正常。由于某些原因,我得到了两个零,将再次检查。可能是尝试此模式
“PasswordText.->(.-)“
谢谢你,迈克。我在通过soap用户界面发送邮件时有一些奇怪的行为,邮递员工作正常。