RSS Feed created using Zend_Feed - firefox prompts to download not display as RSS - zend-framework

I've created an RSS feed using Zend_Feed.
It seems to have worked in that the resulting XML looks good. My problem is that Firefox won't recognise it as an RSS feed and instead prompts me to download the raw XML.
Trying it in IE gives the error "this feed contains code errors" with the following extra info:
Invalid xml declaration.
Line: 2 Character: 3
< ? xml version="1.0" encoding="UTF-8" ?>
Any help greatly appreciated.

The xml-declaration must be on the absolute first line in the output. I.e. no blank lines or spaces before the xml-declaration tag.
This is valid:
<?xml version="1.0" encoding="UTF-8" ?>
This is not:
<?xml version="1.0" encoding="UTF-8" ?>

Check whether <?xml version="1.0" encoding="utf-8"?> is the first line in the feed file. No empty lines or spaces!

If PHP is spitting out any notices/warnings or such, those will malform the feed. Try setting error_reporting to zero before the feed is sent to test:
error_reporting(0);

good rule of thumb when using php class files and such, never ?> your class files. Only use ?> in template-type files where you are going to have regular output afterwards. All of the major packages do this now for exactly the above reasoning.

Related

Extracting data from a webpage where an unusual tag format is used

Note: has to be done in powershell.
I have searched and searched and have this one little problem that I can not seem to solve.
The page is in an unusual form of xml, and looks like this
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://foo.bar.moo.org/">WILBER</string>
This is the only thing on the page. the only part that will ever change is WILBER might be something else.
I have tried:
$site="http://lalaland.org/Getmoocow?input=$foo_name"
$data = (new-object System.Net.WebClient).DownloadString($site)
$foo = [regex]::Matches($data, '<string.*?>(.+)</string>') | % {$_.Captures[0].Groups[1].value}
and a few varients but no luck. the only thing I need is is what is located between the string tags
So, given the string that you presented,
[xml]$x = #"
>> <?xml version="1.0" encoding="utf-8" ?>
>> <string xmlns="http://foo.bar.moo.org/">WILBER</string>
>> "#
>>
$x.string.'#text'
WILBER

Umbraco XSLT RenderTemplate Woes

Needing a little guidance with XSLT and Umbraco. Fairly new to XSLT but I think I understand the concepts. Right on one page I have two columns, each with their own separate pickable content. This is done via the standard content picker property (one for each column). The issue is that I need to be able to have two different templates on the page. So in essence the page navigated two which has the columns has to render two of it's child items in its own page.
I have this working with one column using a generic XSLT which I found that basically just renders what ever child item it finds, but I want it to render what ever one the user picked.
I know the Content Picker returns the XML Node ID of the page and that can be used with the Render Template function to display it (I have an example of that), but when it comes to adding in my own properties and then passing them to the RenderTemplate function I get lost. New to this XSLT :).
So far I have...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"
xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"
xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions"
xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="nodeID" select="data[#alias='leftColumn']"/>
<xsl:template match="/">
<xsl:value-of select="umbraco.library:RenderTemplate($nodeID)" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
Any one know why this doesn't work and how to do what I'm after? The above gives a value was either too large or too small error.
You actually have two problems here ...
Calling RenderTemplate()
RenderTemplate actually requires two arguments when using an alternative template, the first being the content node ID, and the second being the chosen template you want applied.
<xsl:value-of
select="umbraco.library:RenderTemplate($nodeID, $templateID)"
disable-output-escaping="yes" />
See the following link for more information : http://our.umbraco.org/wiki/reference/umbracolibrary/rendertemplate
Too large or too small error
This one is simple to fix by putting an if-empty statement around the the code in question.
<xsl:if test="$nodeID != ''">
<xsl:value-of
select="umbraco.library:RenderTemplate($nodeID, $templateID)"
disable-output-escaping="yes" />
</xsl:if>
The XSLT parser likes to assume certain values are null, when in reality they aren't. Another way to get by this is to check the Skip Errors checkbox when saving, but this makes debugging actual erroneous code a bit of a pain.
Hope it helps.

how to extract xml tag values from email body?

I know the process to extract the body from the email using MIME::PARSER, but in my mail i have xml data. whats is the process to extract xml tag values from the email body?
Body:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<TEST>
<test>test</test>
<test1>test1</test1>
</TEST>
Assuming the body actually consists of XML, just feed it into your XML parser of choice (XML::Twig seems popular these days or you could look at Task::Kensho's recommended XML modules) and use it as normal.

NSXMLParser error, how to get rid of invalid chars inside XML tags?

Hi everyone and thanks in advance for your help.
This is the situation:
I'm consuming a webservice that returns me a soap message in the following way:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getMessagesResponse xmlns="urn:DefaultNamespace">
<getMessagesReturn xmlns="">
<?xml version="1.0" encoding="ISO-8859-1" ?>
<contact>
A message with escaped values like & < >
</contact>
</getMessagesReturn>
</getMessagesResponse>
</soapenv:Body>
</soapenv:Envelope>
I use NSUTF8StringEncoding to read the getMessagesReturn child and it generates me the following:
<?xml version="1.0" encoding="ISO-8859-1">
<contact>
A message with escaped values like & < >
</contact>;
My problem is that it also unescape the & < > inside the contact tag, and of course the NSXMLParser throws an error because these are invalid characters inside a XML tag.
My Question is, How can I avoid this? Is there a way to escape back only the tags message contents before passing the info to the Parser?
Any help would be greatly appreciated.
Edit I use:
[NSString stringWithCString:(char*)elementText encoding:NSUTF8StringEncoding];
Do you control the web service? The correct way to pass getMessageReturn is with a CDATA. Otherwise, the correct encoding would be like this (note the message itself and the extra &amp's)
<getMessagesReturn xmlns="">
<?xml version="1.0" encoding="ISO-8859-1" ?>
<contact>
A message with escaped values like &amp; &lt; &gt;
</contact>
</getMessagesReturn>
But CDATA is much easier, and this is what it's for. If nothing else, you can use string substitution to insert the CDATA before parsing.

XML based template engine in Java?

Can somebody suggest me a template engine (preferably written in Java) that could generate any text that I like from given XML input?
StringTemplate, FreeMarker
How about XSLt? You may use JAXP to do the processing.
You can use XSLT, it is not restricted to generating only XML output. It is restricted to XML input. Use the xsl:output tag do define the type of output you will be generating.
E.g. to generate text output
<xsl:output method="text" encoding="UTF-8"/>
To generate XML output with indentation
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>