I was wondering how I can pass a parsed xml in different java classes within the same project. For example, I have
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try
{
DocumentBuilder builder = factory. newDocumentBuilder();
Document document = builder.parse("Companies.xml");
etc.
And I can parse through it and do what I need to do in main, but I would like to be able to split up this process into different classes. I would have a class for employees, departments, etc. But when I do this in main I can simply say, NodeList EmployeeList = document.getElementsByTagName("employees");. But if I were to try this in a different class it wouldnt have access to document. So how can I use the document in a different class, or do I have to create a new "document" file in every class? Thanks!
No comments:
Post a Comment