pub.xml:xmlStringToXMLNode and XMLNodeToDocument are indeed the services to enforce well-formed XML (or allow non well-formed). xmlStringToXMLNode does some basic validation (e.g. matching tags) but it allows data leading up to the prolog/first tag and ignores it. In other cases, docs that are not well-formed generate errors.
I’ve seen threads that describe various parsers that ignore whitespace in front of the prolog, something that is supposedly against XML rules but I can’t find anything that says that explicitly. The parser in Integration Server clearly allows any amount of junk prior to the prolog. It will even successfully parse with leading junk in front of the first tag when no prolog is present. Very forgiving.
IMO, Mark’s suggestion to just strip the leading junk using built-in services is the path of least resistance. If you really, really need to detect leading junk, detecting that the first character is a ‘<’ should be sufficient–xmlStringToXMLNode and xmlNodeToDocument should be able to do the rest. Or you could swap out the XML parser and use one that detects leading junk but that’s most likely more hassle than it’s worth.