lua-users home
lua-l archive

Unexpected type problem

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I am new to Lua and I have run into something I do not know how to handle. I am converting some VB.NET code to Lua to run in a Luanet (Lua 5.0.2) environment. The code fragment below is supposed to take an XML document contained in a string and extract the inner text value for the XML tag <MessageContent> which is then to be analysed. In the VB case the result of accessing the InnerText property of a node returns a string. However, when the code containing the fragment below is run, the string.find call causes an exception, the description of which indicates that the first parameter (messageContents) is a table and not a string. Can someone tell me what I am doing wrong please.
Thanks,
Paul Wilson
(paul@paulwilsonconsulting.com)
Code Fragment:
 -- Extract the message contents
 xmlDocument = luanet.import_type("System.Xml.XmlDocument");
 local document = xmlDocument();
 document:LoadXml(myMessage);
 -- Attempt to get the message content string
 local nodes = document:GetElementsByTagName("MessageContent");
 local messageContents = "";
 if nodes.Count == 0 then
.
 .
 .
elseif nodes.Count > 1 then .
 .
 .
else -- Save the message contents
 messageContents = nodes[0].InnerText;
 end
 -- Look for multiple messages
 index = string.find(messageContents, ">");
begin:vcard
fn:Paul Wilson
n:Wilson;Paul
org:Paul Wilson Consulting
adr:;;P.O. Box 87;Seba Beach;Alberta;T0E 2B0;Canada
email;internet:paul@paulwilsonconsulting.com
title:Senior Consultant
tel;work:+1.780.951.3521
tel;fax:+1.928.396.4532
tel;home:+1.780.797.4214
tel;cell:+1.780.951.3521
url:http://www.paulwilsonconsulting.com
version:2.1
end:vcard

AltStyle によって変換されたページ (->オリジナル) /