Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to change my DOM tree by removing all nodes except some.
For example, if I want my new DOM to have one of the leaf nodes of the old one, everything needs to be deleted expect the leaf and everyone of his parents (ancestors). Basically I have a list of nodes at some depth that need to be saved and everything else removed.
Iterating on every level to remove nodes takes to much time. I also tried approaching this using "ancestor-or-self" with xpath but that's not helping me delete nodes.
XSLT is designed for this job; it can be called from Java, and it can operate on DOM trees. Basically the rules you outline in your question translate directly into template rules in XSLT, but to give you examples I would need a more precise specification.
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 debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm doing a code cleanup and I want your HELP
The code creates units and place them in a unitPositionHashmap. Furthermore it reduces production value according to unit type.
I'm looking for a way to reduce the amount of code and smarter way to structure this method, so I avoide almost dublicated code.
The code
Create a method having one if block and use parameters to fill in the variable values (p, GameConstants value (like ARCHER), ProductionAmount condition value (like 10). You'll have one if left in the makeUnit method, while having only one if in the new method.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have 200 folders with up to 20 files in each folder. Total the dataset is 2gb. I tried parsing all at once and put each line into a list and sort them but i get out of memory.
What approach could I use to sort the multiple files into on single file?
File-based merge-sort:
Sort content of each file.
Merge sort the 20 files of each folder to get one sorted file per folder.
Merge sort the 200 folder-files to get final result.
If you don't want to do a 200-way merge sort, you can split #3 into multiple merge-sorts and then merge-sort the results of those, to as many levels as needed.
What sorting algorithm do you use? Because I think the problem lies with the algorithm; you need to take a look for a more efficient algorithm to do the sorting. I believe that for large inputs, Merge-Sort is the best (albeit with a few modifications for that size).
Here is a very similar question, take a look at the top two answers. They should help you solve the problem.
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 9 years ago.
Improve this question
I am looking for a standard technology to drive the generation of an XML document based on an XSD and a set of rules. Basically I have XSDs that tell me what the XML should look like and what elements are mandatory or optional. What is not in the XSDs is a set of business rules that say things like "if such element's value is this, that other element is actually mandatory" or "if such element's value is that, that other element should be omitted".
What I have in mind is something that would process the XSDs along with the rules (maybe expressed in something like XPath) and call back my code to generate the mandatory values. The structure of the final document would change dynamically depending on the values of the elements driving the conditions.
I guess I could do something close to what I want with XSLTs. I'd generate all the values with and then use an XSLT to enforce the conditions. But in my case some values maybe take long to produce so I want to avoid computing unnecessary values, meaning values that will be later discarded by the business rules.
Does such a technology exist? FYI I am coding in Java but I am hoping to find a generic technology if possible.
Cheers,
Tom
The problem you described can probably be handled by Schematron. It can be used with XML Schema, and if you already know XPath and XSLT you won't find it difficult to understand. If can specify complex relationships between unrelated nodes based on values and context beyond the abilities of XML Schema.
The specification and many tutorials you can find in the Schematron website.
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 6 years ago.
Improve this question
I have been learning how to build android apps this summer. I am currently trying to work on xml parsing which falls under java in this case. I have a few questions that are mostly conceptual and one specific one.
First, in most of the examples I have seen pages already in xml are used. Can I use a page in regular html format and with whatever the program does turn it to xml and then parse it? Or is that what is normally done anyway?
Secondly, I could use a little explanation on how the parser actually works and saves the data so I will better know how to use it (extract it from whatever it is saved in), when the parsing is done.
So for my specific example I am trying to work with some weather data from the NWS. My program will take the data from this page, and after some user input take you to a page like this, which sometimes will have various alerts. I want to select certain ones. This is what I could use help with. I haven't really coded anything on that yet because I don't know what I am doing.
If I need to clarify or rephrase anything in here I am happy too and let me know. I am trying to be a good contributor on here!
Yes you can parse HTML and there are many parsers available too, there is a question about it here Parse HTML in Android, then we have an answer here about parsing html https://stackoverflow.com/a/7114346/826657
Although its a bad idea, as the tag names aren't well named, so you will have to write lots of code searching attributes for a specific data tag, so you always have to prefer XML,for saving lots of code space and also time.
Here is a text from CodingHorror which says at general parsing html is a bad idea.
http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html
Here is something which explains parsing an XML document using XML PullParser http://www.ibm.com/developerworks/library/x-android/