Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to start from a given file(i.e. a.html) and if I see a pattern as like that:
<!--$include file="b.html"-->
I will go that file(b.html) and take whatever it has and all files will be written as into a final file(i.e. output.html)
If I see an include at b.html I should follow that include too and take whatever it has and I should repeat it recursively at Java?
Any ideas?
PS: It is similar to what jsp:include does but I want to implement it myself. I will implement it as a Maven plugin and I constructed a maven plugin for my need however using recursion or not and using a regex pattern or any other efficient way is what I am looking for.
You need to create a function to get files list, e.g. getFileList(htmlFile:File): File[];
Create a readline function and create a function to parse line which pattern is like "^.*<!\\-\\-\\$include file\\=\"(.+)\\.(html|htm)\" \\-\\->.*$", this is a regular expression, it can match what your searched regex. let's defined the function's name as checkRule(line:String):boolean
If checkRule return true, and get file name, then recursively invoke getFileList by passing just found file name.
Be careful about infinite loop. For example, a.html includes b.html, and b.html includes a.html, it would become infinite loop. So you need to check file list to ignore the file.
Good luck!!!
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
driver.findElement(By.xpath("//*[#id=\"__box23-arrow\"]")).click();dropdown
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
Thread.sleep(5000);
driver.findElement(By.xpath("//*[#id=\"__item1283-__box23-2\"]")).click();
Every time my xpath changes //*[#id=\"__box23-arrow\ example //*[#id=\"__box24-arrow\, im doing automation for SAP, Can you please give any other solution
If your xpath will always be changing, to get your Selenium code to work atleast there should be some pattern in how it changes, for example it may be dependent on current date. Then you can code accordingly to generate your xpath dynamically every time you run your script. If there is no such pattern and no static content to be able to use contains in xpath, you should check out other tools like Sikuli. It uses image recognition to identify your element. This again assumes that the visible aspect of your element remains same.
There is also a wave of new testing products powered by AI like Testim which are "self healing", meaning they will adapt to changes in the source code. I haven't used them but they are probably what you want.
If you know the beginning of your id which is static throughout in that case you can go for
"//*[#id*='__box']"
This will give you element(s) whose id starts with '__box'
Hope this helps!
You can write dynamic xpath using contains keyword as well.
Please refer example below -
//a[contains(#id, 'ctl00_btnAircraftMapCell')
As per the HTML you have shared with us , You can try with this xpath :
//span[#role='button' and contains(#class,'sapMComboBoxArrow sapMComboBoxBaseArrow sapMComboBoxTextFieldArrow')]
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
How to make TextField that inputs letter than compares it with string? It's Hangman game.
The field itself would not do any of the comparing, it will act only as an input access point. That would mean that the only thing it will do is gather whatever you type in it.
So how do you actually make the comparison? Well you will have to call an underlying method, every time there is something written in the field.
for that method you could use some of Java's build in String functionalities for example you could use:
string.indexOf('a').
If the a is present in string, it returns the index(>=0). If not, it returns -1. So, a non-negative return value means that a is present in the string.
You can use Java Swing to create the UI.
There is a TextBox (JTextField). But mostly the Textbox itself will not write anything in it. A user has to do the writing.
You would like to make it only possible to add one char at a time or you have to check if the text the user entered is at most one char.
After that you can check if the char exists in the word you are looking for.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to track down a java variable in a java file - which variable it got assigned to, which method it was passed to.
How should I begin with?
Should I use line by line parsing or is there any other method?
It looks like you are asked to build a huge mansion; and you start by asking: "should my shovel to dig the cellar be better round; or more rectangular". Meaning: if you don't understand that parsing a java program requires more than "line by line" reading; then you are doomed to fail.
Anyway, depending on your underlying requirements, there are two possible answers:
As suggested by duffymo, you might want to learn using an IDE which allows you to easily identify "variable usage" within a project; and make modifications via "reflection"
Start using a fully fledged Java parser; like https://code.google.com/p/javaparser/wiki/UsingThisParser
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I just started to figure out what regexp is, but I have really limited time!
I have a string in xml like : <myid>1234</myid>, for now my xml is in txt it used to be an xml document.
How can I make pattern to extract 1234 from <myid> tag.
If it really looks like this:
<myid>1234</myid>
...you can extract it like this:
Matcher match = Pattern.compile("<myid>(\d+)</myid>").matcher(str);
...and then use the matcher repeatedly, getting the value from the capture group.
But there's a reason everyone is telling you to use a proper parser. There are lots of ways the above can fail, both matching inappropriately and failing to match when it should.
The proper solution is to make the XML valid, and then parse it, and use XPath or similar to read the values.
If you really have some tool requiring you to send it invalid XML, you need to replace that tool. More likely, though, it's some misunderstanding.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
So, I want it to be very easy to create all the entities of my game and for other people to come in and do the same. I was thinking I could just let the users/myself create an XML sheet the stores all the properties of each block (Like a Terraria or Minecraft voxel) and add Lua scripts that are referenced in the XML for additional functionality of any of the blocks.
I'm starting to think It would just be easier to let the user create a JAR file full of classes for each block. And then that JAR file could easily be used to get all the blocks. It'd just be interesting to reference all the blocks by a block id without storing all the classes by ID. Or I could give each class a static id. But that's not important.
Okay, so my short question is what are the pros and cons of storing all the the different types of blocks as classes versus in an XML sheet with Lua for additional functionality?
UPDATE: It looks like I'll be using pure Lua! Looks like an interesting and effective way to do it!
A limitation of the JAR approach is that your data would need to be compiled before it got used. With XML/Lua the data gets read/interpreted at runtime.
A third option that you did not mention is using straight Lua tables instead of XML. This lets you load the data with a simple "require", "dofile" or similar instead of needing to use a XML library as well.