I have a problem I am trying to resolve. I have xml requests coming in 2 formats
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="urn:x-facebook-com:DEF.plan.services.test">
<OneRequest>
<page_number>1</page_number>
<page_size>25</page_size>
<origin>TEST</origin>
<item_name/>
</OneRequest>
</Request>
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="urn:x-google-com:ABC.plan.services.plans">
<SecondRequest/>
</Request>
In both cases I want to extract the tag name that is the first one after <Request>
. i.e OneRequest
and SecondRequest
(these will be dynamic and there are 100's of them). I tried using regex but did not get exactly what I wanted . Any inputs or suggestions will be greatly appreciated.
Also did see posts about xml parsers but it seems an overkill for what I basically want is just the first tag after <Request>
My Attempt
String[] requestTags = requestBody.split("</");
String requestName = requestTags[requestTags.length-2].replaceAll("[^a-zA-Z0-9]",
Not the best it kind of works on the first one but completely messes up in second type