如何使用lua中的字符串find提取xml元素值
我需要使用lua从soap信封中的soap头中提取Username、Password元素值 样本要求-如何使用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
...
<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用户界面发送邮件时有一些奇怪的行为,邮递员工作正常。