Start with the assumption that it is very non-trivial. You've got to simultaneously accomodate the right character set, quoting, conditional escaping, balancing, um, other ugly stuff I can't think of just now. That is, to be a proper XML parser anyway. Its worth the time to get the right software installed instead of faking it.