The other problem with this approach is that it's not taking parent pom files into account.  You can't treat a pom file as a single XML file; you'll have to use a library to parse it, that understands the hierarchy of poms.