java - how to strip pre and post garbage from XML string -


i have xml string contains garbage before , after xml string. there way trim values process xml.

current xml:

--35deuofwdwzmckmxp4z2rsi7reh-y5atoy  content-disposition: form-data; name="file"; filename="uidoc6379937292471437665.xml5114968690793017785.tmp"  content-type: application/octet-stream <?xml version="1.0" encoding="utf-8" standalone="no"?> <product xmlns="http://www.example.com/abc/2014/product">     <timestamp>2017-04-06t04:00:02.387z</timestamp> </product> --35deuofwdwzmckmxp4z2rsi7reh-y5atoy-- 

new xml:

<?xml version="1.0" encoding="utf-8" standalone="no"?> <product xmlns="http://www.example.com/abc/2014/product">     <timestamp>2017-04-06t04:00:02.387z</timestamp> </product> 

it depends on how know xml. if it's above can do:

int start = source.indexof("<?xml"); source = source.remove(0, start); int end = source.indexof("</product>") + "</product>".length; source = source.remove(end, source.length-end); 

a little more error checking appropriate.
assuming c# here, other programming languages have similar constructs.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -