Parsing a XML File in iPhone - 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.

Related

Can StaxEventItemWriter be used to write complex XMLs?

I want to write an XML in below format:
<Parent>
<TotalEmployees>2</TotalEmployees>
<CompanyName>ABCD</CompanyName>
<Employee>
<Name>YYYYY</Name>
<Details>
<EmployeeId>12345</EmployeeId>
<Job>Permanent</Job>
</Details>
</Employee>
<Employee>
<Name>XXXXX</Name>
<Details>
<EmployeeId>67892</EmployeeId>
<Job>Contract</Job>
</Details>
</Employee>
</Parent>
The Employee fragement would repeat and the total number of employee statistics is provided in the TotalCount (calculated value).
Is this possible with StaxItemWriter or should I go for custom ItemWriter. I tried to use headercallback but it did not help. Please guide me.

Unable to Add/Modify Mobile Phone field using IPP against QuickBooks desktop

I can't seem to modify or add the Mobile phone field in QuickBooks for QB Desktop. Online works fine, no dice in desktop but according to the XML response of the MOD request it seems to be working fine.
It shows the field being created/modified (idDomain is created, id value generated) however SyncManager never pushes the changes to QuickBooks.
I can modify the Mobile value on the QB side and I'll be able to see that change in my IPP application but no go when heading the other direction.
Here's the XML traces:
http://pastebin.com/qprwAh9z
Any ideas?
I was able to replicate this. The mobile phone number does not sync to the QB desktop file.Seems like a bug.
Please submit a support ticket here:
Link - http://developer.intuit.com/Support/Incident
It looks like, the problem is when you use 'Mobile' in the Phone's 'Tag' field.
Instead of 'Mobile', I tried 'Home' in the Tag field. As an alternate solution you can try the following (I will take a look if there is any constraint in the intermediate QBXML/QBSDK side )
IDS Req
<?xml version="1.0" encoding="UTF-8"?>
<Add xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" RequestId="22f39648c5ab1111988854e808163dc9" xmlns="http://www.intuit.com/sb/cdm/v2">
<ExternalRealmId>657117515</ExternalRealmId>
<Object xsi:type="Customer">
<TypeOf>Person</TypeOf>
<Name>SampleCust-IDS12</Name>
<Address>
...
</Address>
<Address>
...
</Address>
<Phone>
<DeviceType>LandLine</DeviceType>
<FreeFormNumber>0123456789</FreeFormNumber>
<Default>1</Default>
<Tag>Business</Tag>
</Phone>
<Phone>
<DeviceType>LandLine</DeviceType>
<FreeFormNumber>1234567890</FreeFormNumber>
<Default>0</Default>
<Tag>Home</Tag>
</Phone>
...
</Object>
</Add>
Create Response
<RestResponse xmlns="http://www.intuit.com/sb/cdm/v2">
<Success RequestId="22f39648c5ab1111988854e808163dc9">
<PartyRoleRef>
<Id idDomain="NG">1221097</Id>
<SyncToken>1</SyncToken>
<LastUpdatedTime>2013-07-19T11:25:43Z</LastUpdatedTime>
<PartyReferenceId idDomain="NG">1261065</PartyReferenceId>
</PartyRoleRef>
<RequestName>CustomerAdd</RequestName>
<ProcessedTime>2013-07-19T11:25:43Z</ProcessedTime>
</Success>
</RestResponse>
QBXML [ 2nd phone no is coming under AltPhone tag ]
<?qbxml version="9.0" ?>
<QBXML>
<QBXMLMsgsRq onError="continueOnError" newMessageSetID="13ff6ae6e2c76b59e49">
<CustomerAddRq requestID="EsbKeyMapHeader:1221097:0">
<CustomerAdd>
<Name>SampleCust-IDS12</Name>
..
<BillAddress>
...
</BillAddress>
<ShipAddress>
...
</ShipAddress>
<PrintAs>SampleCust</PrintAs>
<Phone>0123456789</Phone>
<AltPhone>1234567890</AltPhone>
<Fax></Fax>
..
</CustomerAddRq>
</QBXMLMsgsRq>
</QBXML>
QB's view [ There is no specific field for Mobile. Mobile/LandLine is kindOf Metadata. I'll check and confirm this behaviour ]
Thanks

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.

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.