Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what to do when parsers changed

 
Mahesh Pinnamaneni
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
Can any one pls solve my problem.
we are using one XML parser for a quiet long time say DOM parser.and due to some contraints we need to change the parser to improve the performance say PDOM parser.Is there any solution to change the parser without involving any code change.I thinks this will happen as per my knowledge of how the JDBC works.
If we consider JDBC:
Assume that we are using oracle driver to get the connection, we will be setting this information in some configuration file and access this. I our programs we will be having connections,statements & resultsets etc to process queries which will not change even if we change the driver.

can any one throw some light on this topic..
thanks & regards,
Mahesh
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mahesh Pinnamaneni:
Dear All,
Can any one pls solve my problem.
we are using one XML parser for a quiet long time say DOM parser.and due to some contraints we need to change the parser to improve the performance say PDOM parser.Is there any solution to change the parser without involving any code change.I thinks this will happen as per my knowledge of how the JDBC works.
If we consider JDBC:
Assume that we are using oracle driver to get the connection, we will be setting this information in some configuration file and access this. I our programs we will be having connections,statements & resultsets etc to process queries which will not change even if we change the driver.

can any one throw some light on this topic..
thanks & regards,
Mahesh


If you have not encapsulated the code for accessing the XML files (using DOM in a separate class), you cant do that without any code change
You have to go and change all the places where u have used DOM to use PDOM


Incase, you are just designing the system, then you can develop a common interface for acceesing the XML documents (that u define) and then in the implemnting class, you can make calls to the parser u are interested in (DOM, JDOM, PDOM ..) and the client wil know only about the interface
(this is the stratgey pattern)
U can find more about this pattern using google

Example

IXmlAccess
{
GetNode();
GetElement();
......
}

//your class that implemnts DOm parser
XmlDomParser implements IXmlAccess
{
private DOMParser parser; // or PDomParser or any vendor parser
GetNode()
{
//Make calls to actual parser function
return parser.GetNode()
}
}

and in your client code u wil have
IXmlParser parser = new XmlDomParser();

and then u can use this across all your code like

parser.GetNode();
parser.GetElement();

If you change the parser to PDOM, u can then develop a class named XmlPDomParser, implement the IXmlParser interface and use PDOM parser inside that class..

then u have to jut change the line
IXmlParser parser = new XmlDomParser();
to
IXmlParser parser = new XmlPDomParser();


and all the calls

parser.GetNode();
parser.GetElement();

will still work

Hope this helps

[ October 02, 2005: Message edited by: Hari Vignesh Padmanaban ]
[ October 02, 2005: Message edited by: Hari Vignesh Padmanaban ]
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your code only uses DOM methods, and the JAXP methods that go with it, it should be just a metter of external configuration to change the parser. That's what JAXP is for: to abstract away the parser details from the code using it. From your post it's not clear whether that's how your code works, though (and I don't know what PDOM is, and if it supports JAXP).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic