How can I produce a stanza message with JSJaC library? - xmpp

I would like to produce a stanza message with JSJaC:
<message to...'
from='..'
type='chat'>
<menu>
<submenu>...</submenu>
<submenu>...</submenu>
</menu>
</message>
The problem is that I don't know from the begining the number of submenus, so I have to use a loop.
I have tried
var msg = new JSJacMessage();
msg.setTo(...);
msg.setType('chat');
msg.appendNode('menu',
for(i=0; i<Number; i++){
msg.appendNode('submenu': i);
});
I get errors. I also tried to make a string and turn it into object, instead of the loop, but with no success.
Any ideas?

Related

Convert XML like String to PySpark Dataframe

I'm using azure.storage.queue's receive_messages() function in databricks to pull messages from a azure queue. The response looks like xml but it is really just a string:
<?xml version="1.0" encoding="utf-16"?>
<root>
<col1>123</col1>
<col2>1</col2>
<col3>Unknown</col3>
<col4>Dog</col4>
<col5>Owner</col5>
<col6>-1</col6>
<col7>Owner</col7>
<col8></col8>
</root>
When I write the response to a list, it looks like:
'<root>\r\n <col1>123</col1>\r\n <col2>1</col2>\r\n <col3>Unknown</col3>\r\n <col4>Dog</col4>\r\n <col5>Owner</col5>\r\n <col6>-1</col6>\r\n <col7>Owner</col7>\r\n <col8></col8>\r\n</root>'
I know that I can split on \r\n with something like:
l = [x.strip().split(' ') for x in a[0].split('\r\n')]
l
This gives:
['root'],
['<col1>123</col1>'],
['<col2>1</col2>'],
['<col3>Unknown</col3>'],
['<col4>Dog</col4>'],
['<col5>Owner</col5>'],
['<col6>-1</col6>'],
['<col7>Owner</col7>'],
['<col8></col8'],
['</root>']]
I'm not sure if this is the best route and I don't want to hard code each value into the spark dataframe, because I need to iterate through all messages in the queue. Looking for a solution that converts each 'col' into a header and then grabs the value between 'tags'.
Here is an answer:
data=[]
for message in response:
#print(message.content)
soup = BeautifulSoup(message.content, "xml")
c=soup.find_all('col1')
c1=soup.find_all('col2')
c2=soup.find_all('col3')
c3=soup.find_all('col4')
c4=soup.find_all('col5')
c5=soup.find_all('col6')
c6=soup.find_all('col7')
c7=soup.find_all('col8')
for i in range(0,len(c)):
rows=[c[i].get_text(),
c1[i].get_text(),
c2[i].get_text(),
c3[i].get_text(),
c4[i].get_text(),
c5[i].get_text(),
c6[i].get_text(),
c7[i].get_text()]
data.append(rows)
#print(data)
out_df = spark.createDataFrame(data,schema = ['c','c1','c2','c3','c4',
'c5','c6','c7'])
This was faster, but requires the response to always be in the same order, which mine is.
data=[]
for message in response:
#print(message.content)
root=etree.fromstring(message.content.encode('utf-16'))
arr=[]
for child in root:
r=child.text
arr.append(r)
data.append(arr)
out_df = spark.createDataFrame(data,schema = ['c','c1','c2','c3','c4',
'c5','c6','c7'])
display(out_df)

"IllegalArgumentException: Argument is not an array" error in processing when using append();

My code is as so...
ArrayList<Ray> rays = new ArrayList<Ray>();
Particle() {
for(int a=0; a < 360; a+=10) {
append(rays, new Ray(position, radians(a)));
}
}
I'm initializing an ArrayList of the class Ray. Then I run through a for loop and am attempting to
append a new Ray() to the list. I get no errors in the editor but whenever I run the code I get the error message: IllegalArgumentException: Argument is not an array
I've looked around and nothing seems to answer my question. Why is this happening?
The append function is for use with arrays (e.g.: rays[]). However rays is an ArrayList. Hence, you need to use the add method:
append(rays, new Ray(position, radians(a)));
rays.add(new Ray(position, radians(a));

CDATA parsing in blackbery10

I am new to blackberry 10 platform I am stuck with XML CDATA parsing . I am currently using QXMLSTREAMREADER and it is efficient to get the attributes but not getting CDATA. The Xml I used is
as follows
<message_list>
<message title = "title1" date = "21-08-2012 10:20">
[CDATA[ Sample data here ]]
</message>
<message title = "title2" date = "21-08-2012 10:20">
[CDATA[Sample data here]]
</message>
</message_list>
Use custom class extend from QXmlDefaultHandler and can parse CDATA there

NServiceBus "CreateBus()" returning null

I am using NServiceBus 2.6.0.1504 on windows server 2003 32 bit.
The log file generated indicates that everything is getting wired up, but for some reason, "CreateBus()" returns null. Ignore my debugging code :)
SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);
var one = Configure.With(typeFinder.GetAssemblies());
var two = one.DefaultBuilder();
var three = two.MsmqSubscriptionStorage();
var four = three.XmlSerializer();
var five = four.MsmqTransport();
var six = five.IsTransactional(false);
var seven = six.PurgeOnStartup(true);
var eight = seven.UnicastBus();
var nine = eight.LoadMessageHandlers();
var ten = nine.ImpersonateSender(false);
var eleven = ten.CreateBus();
if (eleven == null)
throw new Exception("createbus");
var twelve = eleven.Start();
The exception with the message "createbus" always gets thrown.
This works on my dev box with is Windows Server 2008 R2 64 bit.
Here is my config for the web app.
<MsmqSubscriptionStorageConfig Queue="MedXChangeSubcriptions" />
<MsmqTransportConfig InputQueue="MedXChangeForms" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="MethodFactory.MedXChange.Library" Endpoint="MedXChangeWeb" />
</MessageEndpointMappings>
</UnicastBusConfig>
Any ideas? Any help would be greatly appreciated.
NServiceBus will return null if a bus has already been created. So determine if someone is already instantiating a bus for you.
In my scenario, we were inconsistently defining endpoint configurations. In one process, we would implement IConfigureThisEndpoint and then explicitly configure and instantiate a bus. In another process we would inherit from AsA_Publisher which implicitly creates a bus for you; and when it came time to explicitly define our bus' configuration for this other process we would throw NullReferenceException on the fluent CreateBus method. Removing the AsA_Publisher inheritance resolved the issue.
Hope this helps!

Passing query results in a viewbag

This seems like it should be so easy, but I've tried three or four ways to do it (but to no avail).
I'm just trying to put a query result in a viewbag and display it.
I've tried putting a model object list in a ViewBag:
var mesg = from MSG in lemondb.Messages
where MSG.msg == Membership.GetUser().ToString()
select MSG;
ViewBag.messages = MSG;
And then I try to spit it out in a .cshtml:
var message = (List<LemonTrader.Models.Message>)ViewBag.messages; // <--- fails here because it is a string
foreach ( var MSG in message )
{
#Html.Label(MSG.msg)<br />
}
But it says:
Cannot convert type
'System.Data.Entity.Infrastructure.DbQuery'
to
'System.Collections.Generic.List'
So it seems I'm using using the wrong template. How do I spit out a System.Entity.Infrastructure.DbQuery?
I've also tried passing the results through the Viewbag as a list of strings. (Is that a worse way to do it?)
var mesg = from MSG in lemondb.Messages
where MSG.msg == Membership.GetUser().ToString()
select MSG.msg;
ViewBag.messages = mesg;
And spitting it out as a string list:
foreach (var atext in ViewBag.messages as List<string>) { // gets hung up on foreach here (why???)
#Html.Label( atext )
}
And I get this:
Object reference not set to an
instance of an object.
And it points at the "foreach" keyword.
Does that mean there were no messages? Or what?
I wish there was a tutorial showing how to put queryresults in a ViewBag and how to get them out! I've seen tutorials that return an object.ToList() without respect to any kind of "where" mechanism, but no examples to pull out a few, relevant entries and display them.
Try
ViewBag.messages = MSG.ToList();
Also, System.Data.Entity.Infrastructure.DbQuery implements IEnumerable ( http://msdn.microsoft.com/en-us/library/system.data.entity.infrastructure.dbquery(v=vs.103).aspx ) so this should also work:
var message = (IEnumerable<LemonTrader.Models.Message>)ViewBag.messages;