Some files have 'XMLNS' listed, others just 'XSI'. How do I set an alias for the xpath query that will work with either? - msxml

Some files I need to process have this (called the "haves"):
<ApolloDataSet xmlns="http://irisoft.com/ApolloDataSet1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Other files in the same group have this (called the "have-nots"):
<ApolloDataSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
I can set the default namespace for xpath with the below:
.setProperty "SelectionNamespaces", "xmlns:a='http://irisoft.com/ApolloDataSet1.xsd'"
That works for the haves, like a:/Element, but not the have-nots, since the xpath doesn't have the a: alias.
I tried removing the xmlns attribute before processing, in the hopes that I could just use an unaliased path for both, like /Element, but that only worked for the have-nots (the haves just returned nothing).
So is there a way to process both using the same alias, or no alias? I'm trying to either use the same alias for every file, regardless of "xmlns" being listed, or use no alias for either.

Well I resigned to using the workaround I was trying to avoid. But here is an option for this situation until I find a better one. (And forgot to mention - using VBA for this.)
After the domDocument is loaded, I use the getAttribute method to check if the "xmlns" attribute value is null. If it is I form the xpath string with no alias by means of a vbnullstring, which means the xpath query works with the have-not files (i.e. those files with no "xmlns" listed). If it is not null, I use the "xmlns" value to build a string for the setProperty method setting the "SelectionNamespaces" secondary property.
If IsNull(xPOG.DocumentElement.getAttribute("xmlns")) Then
strAlias = vbNullString
Else
strAlias = "a:"
xPOG.setProperty "SelectionNamespaces", _
"xmlns:" & Mid(strAlias, 1, 1) & "='" & xPOG.DocumentElement.getAttribute("xmlns") & "'"
End If
And the resulting processing takes on a rather ugly form of string building that I hoped to avoid.
It sets an IXMLDOMNode to the nodes returned from a selectnodes method using the xPath query with the strAlias variable.
Set xProducts = xPOG.SelectNodes("/" & strAlias & "ApolloDataSet/" _
& strAlias & "Products/" _
& strAlias & "Product/" _
& strAlias & "PR_UPC")
It isn't that it is bad, it just seems to lack elegance & remind me of how little I know sometimes. Which leads me to believe I'm missing some concept that could correct this. But it works, so I'll follow up if I find a better. I did find a kb article that touched on some of the concepts if it helps anyone. I'm using 6.0 though, so good conceptual explanation, just not exactly what I needed.
PRB: MSXML 4.0 Sets the XML Namespace Attribute to an Empty Value for Child Nodes

Related

Search button for a database in vb.net for listview

The code below is not searching, keeps showing error. It is supposed to search for records using a number.
Private Sub btn_search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_search.Click
Me.Sales_fileBindingSource.Filter = "Receipt Number LIKE '" & "%'" & txt_search.Text & "%'"
End Sub
The error being shown is: Syntax error: Missing operand after 'Number' operator.
Click here to see error screenshot
It would make it easier to see what's going on if the code used an interpolated string, so it might end up like:
Me.Sales_fileBindingSource.Filter = $"[Receipt Number] LIKE '%{txt_search.Text}%'"
It is necessary to put the column name in square brackets as it has a space in it - there are examples of the syntax at DataView RowFilter Syntax [C#] (the syntax for the filter is independent of the language).
If you are using an older version of Visual Basic, before interpolated strings were introduced (the year 2015), you'll need something like:
Me.Sales_fileBindingSource.Filter = String.Format("[Receipt Number] LIKE '%{0}%'", txt_search.Text)
which, while a bit longer, still makes it easier to see what is happening than using lots of " & x & "'-type code.
Finally got it! All i had to do was use an under score to join the two words Receipt and Number to one like this "Receipt_Number" Also made other changes like using String.Format. Check code below.
Me.Sales_fileBindingSource.Filter = String.Format("(Convert(Receipt_Number, 'System.String') LIKE '%{0}%')", txt_search.Text)

GoogleAppEngine - query with some custom filter

I am quite new with appEnginy and objectify. However I need to fetch a single row from db to get some value from it. I tried to fetch element by ofy().load().type(Branch.class).filter("parent_branch_id", 0).first() but the result is FirstRef(null). However though when I run following loop:
for(Branch b : ofy().load().type(Branch.class).list()) {
System.out.println(b.id +". "+b.tree_label+" - parent is " +b.parent_branch_id);
};
What do I do wrong?
[edit]
Ofcourse Branch is a database entity, if it matters parent_branch_id is of type long.
If you want a Branch as the result of your request, I think you miss a .now():
Branch branch = ofy().load().type(Branch.class).filter("parent_branch_id", 0).first().now();
It sounds like you don't have an #Index annotation on your parent_branch_id property. When you do ofy().load().type(Branch.class).list(), Objectify is effectively doing a batch get by kind (like doing Query("Branch") with the low-level API) so it doesn't need the property indexes. As soon as you add a filter(), it uses a query.
Assuming you are using Objectify 4, properties are not indexed by default. You can index all the properties in your entity by adding an #Index annotation to the class. The annotation reference provides useful info.
Example from the Objectify API reference:
LoadResult<Thing> th = ofy.load().type(Thing.class).filter("foo", foo).first();
Thing th = ofy.load().type(Thing.class).filter("foo", foo).first().now();
So you need to make sure member "foo" has an #Index and use the now() to fetch the first element. This will return a null if no element is found.
May be "parent_branch_id"in your case is a long, in which case the value must be 0L and not 0.

Trouble with CreateNewSite() bindings -- WMI -- IIS6

I am successfully creating new IIS 6 websites using the CreateNewSite() function, but would like to add an additional two hostname bindings (see below).
Questions:
Does the CreateNewSite() function support multiple hostname bindings?
If so, what is the syntax? In all the example code I've found out there, I only find copies of the original MS code, with no examples of additional bindings, or even examples of modification functions.
I have already reviewed this blog page...
http://stweet.wordpress.com/2010/03/15/creating-a-new-website-programmatically-on-iis-using-asp-net/
... and while I saw something that looked like multiple domains, the code format was different, and so I'm not sure how it relates to the VBS I am using.
Thanks,
Mik
`
Bindings = Array(0)
Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_()
Bindings(0).IP = myIPnumber
Bindings(0).Port = "80"
Bindings(0).Hostname = WScript.Arguments(0)
' Create the new Web site using the CreateNewSite method of the IIsWebService object.
Dim strSiteObjPath
strSiteObjPath = serviceObj.CreateNewSite("RF_" & WScript.Arguments(0), Bindings, "D:\websites\" & WScript.Arguments(0) & "\httpdocs", WScript.Arguments(2))
`
The WScript.Arguments(2) is a custom IIS service number.

Google Datastore problem with query on *User* type

On this question I solved the problem of querying Google Datastore to retrieve stuff by user (com.google.appengine.api.users.User) like this:
User user = userService.getCurrentUser();
String select_query = "select from " + Greeting.class.getName();
Query query = pm.newQuery(select_query);
query.setFilter("author == paramAuthor");
query.declareParameters("java.lang.String paramAuthor");
greetings = (List<Greeting>) query.execute(user);
The above works fine - but after a bit of messing around I realized this syntax in not very practical as the need to build more complicated queries arises - so I decided to manually build my filters and now I got for example something like the following (where the filter is usually passed in as a string variable but now is built inline for simplicity):
User user = userService.getCurrentUser();
String select_query = "select from " + Greeting.class.getName();
Query query = pm.newQuery(select_query);
query.setFilter("author == '"+ user.getEmail() +"'");
greetings = (List<Greeting>) query.execute();
Obviously this won't work even if this syntax with field = 'value' is supported by JDOQL and it works fine on other fields (String types and Enums). The other strange thing is that looking at the Data viewer in the app-engine dashboard the 'author' field is stored as type User but the value is 'user#gmail.com', and then again when I set it up as parameter (the case above that works fine) I am declaring the parameter as a String then passing down an instance of User (user) which gets serialized with a simple toString() (I guess).
Anyone any idea?
Using string substitution in query languages is always a bad idea. It's far too easy for a user to break out and mess with your environment, and it introduces a whole collection of encoding issues, etc.
What was wrong with your earlier parameter substitution approach? As far as I'm aware, it supports everything, and it sidesteps any parsing issues. As far as the problem with knowing how many arguments to pass goes, you can use Query.executeWithMap or Query.executeWithArray to execute a query with an unknown number of arguments.

MS Access - open a form taking a field value from a previous form

I have a form in an MS Access database which lists all the landowners consulted with for a new electricity line. At the end of each row is a button which opens another form, showing the details of all consultation, offers made etc.
I am trying to use vb in MS Access to take the contactID and automatically put it in a field in the details form, so that landowner's consultation details will pop up automatically. I am not a vb programmer at all (I have a comp sci degree mostly in Java and I'm currently working as a GIS analyst but it's a small company so I've been asked to get an Access database working).
I want to say
[detailsForm]![contactID] = [landownerlist]![ID]
in a way that vb and access will be happy with. Then I can see if I'm on the right track and if it will actually work! What I have above does not actually work. It won't compile.
From Kaliana
If you wish to open a form to a new record and to set the ID there, you can use Openargs, an argument of Openform:
DoCmd.OpenForm "FormName",,,,acFormAdd,,Me.ID
The opened form would also need some code:
If Me.Openargs<>vbNullstring Then
Me.Id = Me.Openargs
End If
It is also possible to find:
Forms!LandownersList.Recordset.FindFirst "ID=" & Me.ID
or fill in a value:
Forms!LandownersList!Id = Me.ID
on the form being opened from the calling form.
You may want to look into the code that is behind these buttons. If you are using a docmd.openform you can set the 4th Setting to a where clause on openning the next form.
DoCmd.OpenForm "OpenFormName", acNormal, , "[contactID] = " _
& [detailsForm]![contactID] , acFormEdit, acWindowNormal
This assumes contact ID is numeric and doesn't require any quotes.
Using open args is the generally accepted solution, as alluded to by others. This just falls under the category of "For you edification":) One of the problems with using open args is that unless you are careful with your comments it's easy to forget what they were supposed to mean. Were you passing more than one? Which is which? How did I do it here? How did I do it there etc. For my own money, I standardized to this (below) so I can always pass more than one argument without fear, and when I review my code a year from now, I can still see what's what without a huge hassle:
Option Explicit
'Example use: DoCmd.OpenForm "Example", OpenArgs:="Some Filter|True"
Public Enum eForm1Args
eFilter = 0
eIsSpecial = 1
End Enum
Private m_strArgs() As String
Public Property Get Args(ByVal eForm1Args As eForm1Args) As String
Args = m_strArgs(eForm1Args)
End Property
Private Sub Form_Open(Cancel As Integer)
m_strArgs = Split(Nz(Me.OpenArgs, vbNullString), "|")
If LenB(Me.Args(eFilter)) Then Me.Filter = Me.Args(eFilter)
End Sub
Private Sub Command1_Click()
If LCase$(Me.Args(eIsSpecial)) = "true" Then
'Do something special
End If
End Sub
As previously posted OpenArgs is great for this. One trick I have learned is that it is easy to pass in multiple parameters if required as a delimited string (comma for example), the target form can then access these values using the Split() function thus:
StringArrayVariable()= Split(me.OpenArgs,",")
Me.textbox= StringArrayVariable(0)
Me.textbox1= StringArrayVariable(1)
etc.
This is air code so check out the helpfile for Split().
It is also possible to pass objects in OpenArgs as well, it requires some manual memory pointer manipulation and I don't have the code to hand but I'm sure a Google search will find some examples. This technique can cause some random crashes though. Be Warned!

Resources