1

I am calling some XMLRPC API and sometimes I am getting some "dirty" response. Dirty response means that along with XML is returned some other content/html like:

<div>Some Html maybe> Or some additional string is here
<?xml version="1.0" encoding="ISO-8859-1"?>
<methodResponse>
   <params>
      <param>
         <value><int>30</int></value>
      </param>
   </params>
</methodResponse>

I need a way to throw out anything what is not XML and read only XML from string response so from response above I get only:

<?xml version="1.0" encoding="ISO-8859-1"?>
<methodResponse>
   <params>
      <param>
         <value><int>30</int></value>
      </param>
   </params>
</methodResponse>

If nothing it would be helpful if someone provide code which cleans only HTML and left only XML at least. Prefer code in C#

2
  • Well-formed HTML will validate as XML, so it may be easier to strip out any elements that are not in your XML responses (i.e. methodResponse, params, etc.) Commented Jan 10, 2017 at 0:52
  • Can u show the code which gives you the "dirty" response Commented Jan 10, 2017 at 1:29

1 Answer 1

0

Try using a variation of this or possibly use XSLT to filter the response you get back from the API with something similar to this. XSLT is actually pretty powerful stuff when filtering XML. I know Visual Studios didn't support XSLT V.2, but if you could use V.2 in another editor its quiet useful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.