Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search for string in xml file

Status
Not open for further replies.

AnandDuddella

Programmer
Apr 6, 2011
7
GB
Hi I am suing Vb Script regular expression to search for a string in xml file but it does not work always please do let me know any better idea exists

'=======================================================================================
Function check_ObjectLabel_exists(strObjectPath,sourceDoc)
Dim colMatches,ObjRegExp
Dim xmlContainerForQuickSearch

Set ObjRegExp = New RegExp
Set xmlContainerForQuickSearch = Create_XML_DOM_Structure_WithEmbed_HTML_DOM(sourceDoc)
' This above functions loads an html file into xml so that i can do a quick search
ObjRegExp.Pattern = Trim(strObjectPath)
'strObjectpath is the string i am searching for
ObjRegExp.Global = True
ObjRegExp.IgnoreCase = True
Set colMatches = ObjRegExp.Execute(Replace(xmlContainerForQuickSearch.text,"&nbsp",""))

check_ObjectLabel_exists = colMatches.count
End Function

 
In RegExp, the backslash is a special character which you need to escape.
Try this:
Code:
strObjectPath=Replace(strObjectPath,"\","\\")
ObjRegExp.Pattern = Trim(strObjectPath)

Does your path contain any uncommon characters like "#" or "+" or the like?

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Yes but before coming to this function strObjectPath i would strip of all the speak characters and spaces but if the string i am searching is in two words separated by a space then that is an issue which i worked it out by

Set colMatches = ObjRegExp.Execute(Replace(xmlContainerForQuickSearch.xml," ",""))

It works but dont really know whether this is the correct way to do it

Any other way to do it would be a welcome

Thank you in advance

regards
Anand
 
Well, if you strip all said characters, your string won't be the same anymore.
And that is a bad thing indeed if you try to FIND something!

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
yeah i totally agree with what you say but my aim here is to search for a string what user enter which would be present on the UI .So user can enter ignoring cases of a string so in that case to have a standard comparison i convert the string of user to lower cases and strip any special characters or spaces he/she would enter

 
Then what is it that is not functioning?
What does the HTML-XML you are parsing look like?
Does it load properly to begin with?
Are you parsing it properly?
And what do you do once you found that string? Highlight it?
Why do you Create_XML_DOM_Structure_WithEmbed_HTML_DOM at all andy why do you think it quicker than anything else?

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
I am building up a automation framwork for testing internal company crm and our release cycle is everyweek

Things change here very quickly as new features have been added and the UI objects also change .

So we came up with the idea of having a key identification function which manual testers would feed with xpath like langauge to address a UI interface object such as

When user would pass "userNAme" / "username" / "User-Name" it would return him the corresponding html input object to perform any action so the identification is build only once can be re-used and it is more flexible when things change over time

to address another nested UI Object he would address

Billing \ company name

here Billing is the table name which user can see on the interface and we would return the input or any object related to company name

So the first check the identification function should do is to check whether the given UIString exists in the interface

So for now lets ignore the xml or html basic idea is to quickly find the text (given UI string) is present so that we can traverse through the structure

The reason we convert the whole html to xml in few cases is such as where we have to perform one action such as process a action and then compare the UI sturcture ( for example:- billing address has changed so to compare ) we take the snap shot of the html table to store it and perform comparisons later but as we are scripting in VB Script the limitation is that you can not copy objects by value so when working with comparison functions we convert the html into XML and make a copy of it to be compared later stage

I hope i have cleared my reason

Now coming back to the problem of searching i have resolved it so that user can enter a string with special characters or else in any case and i can quickly check whether that exists in the given html or xml document object
 
Please try

1. To perform a case-insensitive regular expression, you should just use objRegEx.ignoreCase = true.

2. You say:

If colMatches.Count = 1 Then
For Each strMatch in

add objRegEx.global = true to your regular expression



Regards
Attune Infocom Pvt. Ltd.
Joomla Template Design | Joomla Web Dvelopment
Email: contact@attuneinfocom.com


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top