We add more iteration methods for our XML classes in the new MBS Xojo XML Plugin for our 22.4 release. You can not just loop over normal nodes, but also over attributes and elements.
In this example we do a for each loop over attributes:
Sub IterateAttributeNodes()
Dim doc As New XMLDocumentMBS("<doc id=""123"" value=""test""></doc>")
Dim root As XMLElementMBS = doc.DocumentElement
For Each e As XMLAttributeMBS In root.IterateAttributeNodes
MessageBox e.Name+": "+e.Value
Next
End Sub
(more)

New in this prerelease of the 22.4 plugins:
- Update Chromium plugin classes to newer Chromium version.
- Added OptionMimeOptions, OptionMaxLifeTimeConnection and OptionSSHHostPublicKeySHA256 properties to CURLSMBS class.
- Fixed LocalName property in XMLNodeMBS class.
- Fixed crash in XMLNodeMBS destructor.
- Optimized string handling for XML plugin.
- Added ReferenceCount property for XMLNodeMBS class.
Download:
monkeybreadsoftware.com/xojo/download/plugin/Prerelease/ or
from DropBox.
Or ask us to be added to our shared DropBox folder.
Just one month till the XDC Developer Retreat 2022 starts in Nashville:
Xojo Developer Retreat 2022, 19th and 20th September 2022.
Please reserve the days from 18th to 21st September in your calendar. You may want to use the weekend to come to Nashville earlier to enjoy the city and then join the get-together on Sunday evening. Two days of conference follows with a special developer adventure on the second day. Yes, instead of lots of sessions in a ballroom, Dana organized something different this time. I bet you'll enjoy it! Be sure sure to stay the night on Tuesday, so you can enjoy the dinner and travel home a day later.
You can either stay in the conference hotel ($269 USD/night) or maybe better get a cheaper hotel outside and drive daily to downtown for the conference. Or maybe you like to share a room when traveling with your colleague?
Since the conference hotel allows you to cancel, it may be good to reserve a room and later rebook it or cancel, when you find a lower rate. See you there!
The Xojo compiler knows a few pragmas, so let's today dive into them:
BackgroundTasks
This flag is valid only within a method and defines whether the Xojo compiler will insert RuntimeBackgroundTask() calls at loop boundaries. This call checks if some time passed, about 60 yields per second at maximum. Then it does a thread switch and passes CPU time to the next waiting thread.
Older name was DisableBackgroundTasks, but that has the meaning of the parameter reversed.
BoundsChecking
This pragma seems to have no effect currently. The array function always raise exceptions.
I think in older compilers before LLVM, the array access was inlined and thus the compiler could leave away the check.
See Issue
39349.
Older name was DisableBoundsChecking, but that has the meaning of the parameter reversed.
(more)

New in this prerelease of the 22.4 plugins:
Download:
monkeybreadsoftware.com/xojo/download/plugin/Prerelease/ or
from DropBox.
Or ask us to be added to our shared DropBox folder.
DynaPDF has a feature to quickly encrypt or decrypt a PDF with the simplified EncryptPDF and DecryptPDF functions. You need an instance of DynaPDFMBS class and then you can call those methods with the right file reference. Pass in the parameters needed like the user password (for viewing) and the owner password (to remove restriction and encryption). We provide several encryption variants, so you can pick the oldest acceptable one. In our example we use 256 bit AES. Here is an example snippet with two example methods:
Sub DecryptPDF(file as Folderitem)
Dim pdf As New DynapdfMBS
pdf.SetLicenseKey "Lite" // For this example you can use a Lite, Pro or Enterprise License
Call pdf.DecryptPDF(File, pdf.kptOwner, "ownerpass")
MsgBox "Decrypted."
Catch d As DynaPDFErrorExceptionMBS
MsgBox "Failed to decrypt PDF: "+d.message
End Sub
Sub EncryptPDF(file as Folderitem)
Dim pdf As New DynapdfMBS
pdf.SetLicenseKey "Lite" // For this example you can use a Lite, Pro or Enterprise License
Dim flags As Integer = pdf.krsPrint // forbit printing
flags = flags Or pdf.krsCopyObj // deny copying content
// userpass to just open and read
// ownerpass to decrypt and remove restrictions
Call pdf.EncryptPDF(File, "userpass", "ownerpass", pdf.kklAES256, flags)
MsgBox "Encrypted."
Catch d As DynaPDFErrorExceptionMBS
MsgBox "Failed to encrypt PDF: "+d.message
End Sub
Please try it, play with the various options on the restrictions. If you make a new PDF with DynaPDF, you can of course also apply the same encryption options for saving the new file. Let us know if you have questions.
Xojo Inc. announced a sale for the next few days:

If you waited to get a Xojo license or to renew your license or to upgrade to Xojo Pro, this is your chance.
As usual, if your Xojo license is up for renewal in August or September, you can update now and enjoy a discount. If your Xojo license expired already, just get a new one. With discount this is cheaper than a regular update.
The add-ons are included in the sale. If you like to get one of the MBS articles there, you can use the sale price at Xojo Store or we match the price if you buy directly from us. Please contact us if you need a MBS Plugin license.

For 20 years we used the built-in XML classes in Xojo. While they do the job basically, we had a desire for years to get something better. We now started to make an alternative implementation of XML classes based on the xerces-c project:
MBS Xojo XML Plugin
Flexibility
By implementing our own classes, we are very flexible on what we support. A lot of utility code we had in various projects to work on xml trees, can now be built-in to the plugin classes and run much faster. Be can also offer more customization on various options.
Unicode support
The new plugin should handle all the unicode details and work well with various text encodings. Usually we use UTF-8 or UTF-16, but we want it to work well with other encodings.
Exceptions
We use exceptions for reporting errors. The exceptions should include all details needed in the message text. As usual our plugin includes for example the index value and the ubound/count value in an OutOfBoundsException.
We like to avoid a couple of common pitfalls, so you can for example freely move nodes between documents. But please avoid recursion in your xml trees.
(more)

New in this prerelease of the 22.4 plugins:
Download:
monkeybreadsoftware.com/xojo/download/plugin/Prerelease/ or
from DropBox.
Or ask us to be added to our shared DropBox folder.
Some of your clients may have MongoDB databases and your application may need to connect and insert a record. Here is a bit of sample code on how to this:
Sub Action()
// prepare URI to servers
Dim URI As New MongoURIMBS("mongodb://localhost/")
// optionally with authentication
'URI.UserName = "test"
'URI.Password = "secret"
// connect
Dim client As New MongoClientMBS(URI)
// pick database
Dim database As MongoDatabaseMBS = client.Database("test")
// pick collection
Dim collection As MongoCollectionMBS = database.Collection("clients")
// now build a record as JSON
Dim NewRecord As New JSONItem
NewRecord.Value("firstName") = "Bob"
NewRecord.Value("lastName") = "Jones"
NewRecord.Value("city") = "Los Angeles"
NewRecord.Value("phone") = "555-1234-567"
// and insert
Dim Result As String = Collection.InsertOne(NewRecord.toString)
Dim j As New JSONItem(Result)
Dim n As Integer = j.Lookup("insertedCount",0)
If n = 1 then
MessageBox "Record saved"
Else
MessageBox "Failed to insert: "
End If
Exception m As MongoExceptionMBS
MessageBox m.message
End Sub
As you see we use our MongoURIMBS class to prepare the connection data like the server URL, port, user name and password. Then we use MongoClientMBS class to establish a connection. We select which database and collection (table) to use and finally insert our record as JSON to it.
Optionally the new InsertMany function in the upcoming 22.4 plugin can be used to insert multiple documents at once. You would pass either a JSON Array with the records or a Xojo array with the JSON objects.
Please try and let us know if it works or whether you have questions.