how to extract xml tag values from email body? - perl

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.

Related

Parsing a XML File in iPhone

I need to parse a XML file from the website.I have went through some links like ray wenderlich,etc.,But first i need to know how the XML parsing is working. So i have decided to parse a simple xml file which is given below.
<?xml version="1.0" encoding="UTF-8"?>
<employees>
<emp id = "100" name = "Cyril">
<details>
<desc>This Employee is working in this company for the past 5 years
</desc>
<age>35</age>
</details>
</emp>
<emp id = "101" name = "Ram">
<details>
<desc>This Employee is working in this company for the past 3 years
</desc>
<age>28</age>
</details>
</emp>
</employees>
Can anyone help me ?
you can use NSXMLParser for the same and you need to implement its delegates where you will receive the parsed values.

what is the metadata attribute pair in MQFTE ? Why is it used?

I am working with wmqfte. While creating a transfer there is a parameter for metadata attribute pair. Why is this used for ?
One of the FTE engagements I worked on required email notifications of transfer status. Our approach to this was to add an email step in the transfer and the way we passed in the source and destination addresses was with metadata pairs. The transfer XML is provided below for an example:
<?xml version="1.0" encoding="UTF-8"?><request version="4.00" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
<!DOCTYPE request>
<managedTransfer>
<originator>
<hostName>host.example.com</hostName>
<userID>me</userID>
</originator>
<sourceAgent QMgr="QMGR01" agent="AGENT01"/>
<destinationAgent QMgr="QMGR02" agent="AGENT02"/>
<transferSet priority="5">
<metaDataSet>
<metaData key="email.from">fteadmin#example.com</metaData>
<metaData key="email.to">"dept#example.com</metaData>
</metaDataSet>
<item checksumMethod="MD5" mode="binary">
<source disposition="delete" recursive="false">
<file>/root/path/file</file>
</source>
<destination exist="overwrite" type="directory">
<file>/root/path/</file>
</destination>
</item>
</transferSet>
<job>
<name>Your Job Name Here</name>
</job>
</managedTransfer>
</request>
A better way of sending status emails is to watch the transfer notifications published at the Coordination QMgr. However this example does show one possible use for the metadata pairs.

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"/>

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

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.