Friday 24 January 2014

Java program to read xml file-Object-Repository.xml


OR.xml is below:
<?xml version="1.0" encoding="UTF-8"?>


<OR>
    <Page name="page1">
        <Object name = 'pg1obj1'>
            <propertytype>id </propertytype>
             <propertyvalue>//*[@id='pg1obj1'] </propertyvalue>
        </Object>
        <Object name = 'pg1obj2'>
            <propertytype>classname </propertytype>
             <propertyvalue>//*[@classname='pg1obj2'] </propertyvalue>
        </Object>
    </Page>
   
    <Page name="page2">
         <Object name = 'pg2obj1'> 
                <propertytype>xpath </propertytype>
                <propertyvalue>//*[@xpath='pg2obj1']</propertyvalue>         
            </Object>
            <Object name = 'pg2obj2'>
            <propertytype>linktext </propertytype>
             <propertyvalue>//*[@linktext='pg2obj2'] </propertyvalue>
        </Object>   
    </Page>
</OR>


Java Program to read or.xml file
package programs;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
public class ORxml {
    public static void main(String arg[]) {
        try {
            File inputfile = new File(System.getProperty("user.dir")
                    + "\\OR.xml");
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory
                    .newInstance();
            DocumentBuilder docbuilder = dbFactory.newDocumentBuilder();
            Document doc = docbuilder.parse(inputfile);
            doc.getDocumentElement().normalize();
            System.out.println("Root element :"
                    + doc.getDocumentElement().getNodeName());
            NodeList nodelist = doc.getElementsByTagName("Object");
            System.out.println("##################################");
            for (int tmp = 0; tmp < nodelist.getLength(); tmp++) {
                Node nNode = nodelist.item(tmp);
                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element) nNode;
                    System.out.println("object name : "
                            + eElement.getAttribute("name"));
                    System.out.println("propertytype : "
                            + eElement.getElementsByTagName("propertytype")
                            .item(0).getTextContent());
                    System.out.println("propertyvalue: "
                            + eElement.getElementsByTagName("propertyvalue")
                            .item(0).getTextContent());
                    System.out.println("--------------------------------------");
                }
            }
        } catch (Exception e) {
            e.getMessage();
            e.printStackTrace();
        }
    }

}



Back to selenium interview questions and Answers

Back to Java interview questions and Answers


17 comments:

  1. Thanks for the great information in your blog Selenium

    ReplyDelete
  2. Thanks for the great information in your blog Selenium

    ReplyDelete
  3. Thanks for the great information in your blog Selenium Training in Chennai

    ReplyDelete
  4. Selenium is not just a single tool or a utility, rather a package of several testing tools and for the same reason it is referred to as a Suite. This blog gives great view for selenium beginners. Learn Selenium from the best Selenium Online Training in your locality at CatchExperts.com

    ReplyDelete
  5. the best and very useful blogs for learner each and every concept explain in easy way thank you for sharing such a nice content.keep on update latest information all the best
    Selenium Online Training usa|uk|canada|australia

    ReplyDelete
  6. I also want to know the differences selenium IDE, selenium RC and web driver. Can you tell me about it.

    Selenium Training in Chennai

    ReplyDelete
  7. Thanks for sharing great information in your blog.each topic is explained very well.One of the recommanded.we refere your blog to the learners and professionals.please update with new concepts.


    Selenium Online Training in hyderabad

    Testing tools Online Training in USA|UK|AUSTRALIA|SOUTH AFRICA

    ReplyDelete
  8. Thanks for sharing great information in your blog.each topic is explained very well.One of the recommanded.we refere your blog to the learners and professionals.please update with new concepts.


    Selenium Online Training in hyderabad

    Testing tools Online Training in USA|UK|AUSTRALIA|SOUTH AFRICA

    ReplyDelete
  9. Well explained. Got to learn new things from your Blog on Appium.Appium training in chennai

    ReplyDelete
  10. SELENIUM
    From My search…Creating Experts provides Best Selenium Training with real time projects assistance.Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.They also provide placement assistance in leading MNC companies across the globe according to the current requirements.
    And these are the Best selenium training institute which provides Real Time Hands on Training…
    http://thecreatingexperts.com/selenium-training-in-chennai/
    Codedion Technologies-9003085882
    Creating Experts-8122241286
    They also providing both Classroom/Online Training

    ReplyDelete
  11. Nice Article, Croma Campus is the pioneer of instruction giving the Selenium Training in Noida

    ReplyDelete
  12. Appreciable! The training is conducted by subject specialist corporate professionals with wide experience in managing real-time ethical hackingtraining/ cyber security projects. Indian Cyber Army implements a blend of academic learning and practical sessions to give the candidate optimum exposure. https://www.ica.in/blog/ethical-hacking-training

    ReplyDelete
  13. Ꮃhen someone writeѕ ɑn piece of writing he/shе maintains
    the plan of a user in his/her mind that how a user
    can be aware of it. Thuѕ that'ѕ why this artiсⅼe is perfect.

    Thаnks!
    great post to read : How To Password Protect Folder With Minimum Effort And Still
    Leave People Amazed

    ReplyDelete
  14. 有趣話題提供最新的網路話題,內容豐富多元包含娛樂,趣味,科技,動漫,遊戲,汽車,美食,健康,寵物,旅遊,時尚,家居,文化,歷史,親子等最新最流行的話題,讓心情快樂一整天。

    ReplyDelete