How to Show & in xml constructed from string - asp.net

I am creating a web api using asp.net mvc4 and the response output is xml. Before outuptting to browser I modify the xml response so that one of the values between the start and closing tags contain a url string which may have '&'
When outputting in browser, this generates an error that xml is not well formed.
I have read from How to show & in a XML attribute That would be produced by XSLT that one can use D-O-E to generate unescaped content using xslt
but dont know how this could apply for xml generated from a string and displayed in browser

You should encode the & as
&
which is understood by XML (see http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined%5Fentities%5Fin%5FXML)
Another alternative would be to surround the output in a CDATA tag (http://stackoverflow.com/questions/2784183/what-does-cdata-in-xml-mean)

Related

How to handle special characters (such as "&") in Convert Query Params to XML of datapower

I am new to datapower, so I am sorry its silly question.
I have create one flow in datapower whose request and response type is Non-XML.
when I try to post an XML to my flow I am getting following error.
Convert HTTP produced invalid XML: mismatched tag, expected employed_by at offset
here is the sample request XML :-
...
<emp_status type="employed" />
<employed_by>abc & company</employed_by>
<work_phone_no>XXXXX</work_phone_no>
<years_employed>10</years_employed>
<months_employed>10</months_employed>
...
but If I remove & from the request XML then my flow works fine.
If it is query string then &-sign is %26 and not &!
If it is non-xml you are going for I'd recommend using GatewayScript instead for all parsing!

scrape xml from a html page with getNodeSet

Hi I am using R to do some basic web scraping where I am comfortable parsing xml file and querying them with xpath. However I am having difficulty parsing a full html page and trying to extract the xml to get into my comfort zone. For example:
parsedhtml <- htmlParse("http://www.w3schools.com/XPath/xpath_examples.asp")
parses the html. I am using this because xmlParse only works on .xml files. I know that by using getNodeSet I can isolated specific nodes within the parsed html. So I am attempting to extract the embedded xml document under the "The Example XML Document" section by trying:
getNodeSet(parsedhtml, "//div[#class = 'code notranslate']")
where I get the data in the correct node, however it is not in standard xml and I am unable to parse this using xmlParse. My question is how do I use the result of getNodeSet to extract the xml?
Thanks very much

getting the content of an invalid Xml Document in Biztalk

I have a Biztalk orchestration that posts to a http site. the response that comes back is of xmlDocument type, but it only contains a 0, no html/xml at all. All I want to do is set that 0 to a string or something to output it, but I cannot use any of the xmldocument functions because the xml is not well formed, and I cant use maps because there is no schema to work with. Trying to use any xml function returns an "invalid root level" error.
You can use a string variable and use Xpath to set the value from the response message in an Expression Shape.
You can use a XMLDocument Message and create it in an Assign Shape. You can assign the string variable to an element in the message.
You might look at using a Pipeline Component to wrap the response - e.g. have a look at the Flat File samples here

Need to way to grab an XML file from an URL, transform it with XSL, and present it back as a XML file that prompts a save?

Requirements:
Raw XML is from external website I have little control via URL (eg. http://example.com/raw.xml)
I need to transform it via XSL into another XML file (I already have this XSL file written and it works)
I need to write an asp.net or asp file that takes the url, applies the xsl transform, and outputs the resultant xml that prompts the client to save the xml to the client local disk
End result is a xml file that has been xsl transformed, based on xsl and xml from external website
This should not be difficult, but I do not see any examples that allow me to do what is stated above. Please help! Thanks in advance!
You can get the external XML using the WebRequest class (for example).
The result can be loaded to an XML document and transformed - the transformed document can then be returned on the HttpResponse.OutputStream with the correct headers for an XML document (response-type will be either text/xml or application/xml).

Regular expression to replace & with & in XML file

In an XML file, I am capturing a long list of URLS from a web page, using regex (in .NET). Within the captured URLS, I simply need to substitute '&' for all '&' that are located within the URLS. How do I do this?
If you do this and save the results, you'll be left with invalid xml. If you are using a real xml parser the & will be correctly returned as & at the time you read it.
If you insist on proceeding, a simple String.Replace("&", "&") on each url should suffice.
Rather than a regex I'd suggest using the String.Replace("&","&") string function.
Why don't you do just:
string.Join("\n", System.IO.File.ReadAllLines("file.txt")).Replace("&", "&");
?

Resources