How to store an XML document in Mac OS X?

2

1

Firstly, I opened TextEdit. Went to Format Menu & I set option -> Make Plain Text, I entered following Data, Which is to be required in my Application.

<?xml version="1.0" encoding="ISO-8859-1"><tips><Prop_Tips><Tip_ID><![CDATA[1]]></Tip_ID><Category_ID>1</Category_ID><Tip_Title>Play Your Shot</Tip_Title><Tip_Thumb>http://192.168.32.212/jalpesh/igolf/TipThumb/PlayyrshotThumb.jpg</Tip_Thumb><Tip_image>http://192.168.32.212/jalpesh/igolf/TipImage/Playyrshot.jpg</Tip_image><Tip_Description>Every golfer likes to hit the ball long, high and straight, but experience tells you that you can expect a certain pattern to your shots.</Tip_Description><Category_Name>Course Management/Strategy</Category_Name></Prop_Tips><Prop_Tips><Tip_ID><![CDATA[2]]></Tip_ID><Category_ID>1</Category_ID><Tip_Title>Shots Curve From Sidehill Lies</Tip_Title><Tip_Thumb>http://192.168.32.212/jalpesh/igolf/TipThumb/Shots-Curve-From-Sidehill-LiesThumb.jpg</Tip_Thumb><Tip_image>http://192.168.32.212/jalpesh/igolf/TipImage/Shots-Curve-From-Sidehill-Lies.jpg</Tip_image><Tip_Description>Sidehill fairway lies will cause the ball to curve, slice right or hook left. Here's a tip to help make better contact.</Tip_Description><Category_Name>Course Management/Strategy</Category_Name></Prop_Tips></tips>

After saving this file as UTF-8, Whenever I tried to read my XML file through XMLParser, I am getting following data from file

{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf460
{\fonttbl\f0\fmodern\fcharset0 Courier-Bold;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx480\tx960\tx1440\tx1920\tx2400\tx2880\tx3360\tx3840\tx4320\tx4800\tx5280\tx5760\tx6240\tx6720\tx7200\tx7680\tx8160\tx8640\tx9120\tx9600\tx10080\tx10560\tx11040\tx11520\tx12000\tx12480\tx12960\tx13440\tx13920\tx14400\tx14880\tx15360\tx15840\tx16320\tx16800\tx17280\tx17760\tx18240\tx18720\tx19200\tx19680\tx20160\tx20640\tx21120\tx21600\tx22080\tx22560\tx23040\tx23520\tx24000\tx24480\tx24960\tx25440\tx25920\tx26400\tx26880\tx27360\tx27840\tx28320\tx28800\tx29280\tx29760\tx30240\tx30720\tx31200\tx31680\tx32160\tx32640\tx33120\tx33600\tx34080\tx34560\tx35040\tx35520\tx36000\tx36480\tx36960\tx37440\tx37920\tx38400\tx38880\tx39360\tx39840\tx40320\tx40800\tx41280\tx41760\tx42240\tx42720\tx43200\tx43680\tx44160\tx44640\tx45120\tx45600\tx46080\tx46560\tx47040\tx47520\tx48000\ql\qnatural\pardirnatural

\f0\b\fs24 \cf0 \CocoaLigature0 <?xml version="1.0" encoding="ISO-8859-1"?>\
    <tips><Prop_Tips><Tip_ID><![CDATA[1]]></Tip_ID><Tip_Title>Play Your Shot</Tip_Title><Tip_Description>Every golfer likes to hit the ball long, high and straight, but experience tells you that you can expect a certain pattern to your shots.</Tip_Description></Prop_Tips><Prop_Tips><Tip_ID><![CDATA[2]]></Tip_ID><Tip_Title>Shots Curve From Sidehill Lies</Tip_Title><Tip_Description>Sidehill fairway lies will cause the ball to curve, slice right or hook left. Here's a tip to help make better contact.</Tip_Description></Prop_Tips><Prop_Tips><Tip_ID><![CDATA[3]]></Tip_ID><Tip_Title>Don't Ground The Driver</Tip_Title><Tip_Description>Keep the clubhead just off the ground to get your swing off to a consistently smooth start.</Tip_Description></Prop_Tips><Prop_Tips><Tip_ID><![CDATA[4]]></Tip_ID><Tip_Title>Tilt Your Tee</Tip_Title><Tip_Description>Here's a tip to "max out" into-the-wind drives.</Tip_Description></Prop_Tips></tips>}

Which indicates that, file isn't stored in proper format.

I want to simply save an XML file using TextEdit in Mac OS X.

Sagar R. Kothari

Posted 2009-08-24T22:34:02.150

Reputation: 4 267

You may want to save it as ISO-8859-1, not UTF-8, as things can go funny with XML if it's not in the encoding it says it is. – TRiG – 2017-03-12T21:56:08.327

Answers

8

It looks like your file was saved as RTF, containing all that extra data you saw.

To switch TextEdit over to Plain Text Mode, press ⇧⌘T (Shift-Command-T), or select "Make Plain Text" from the Format menu.

before

after

If you're doing a lot of code editing, I also recommend getting TextMate, a proper code editor with XML support:

enter image description here

jtbandes

Posted 2009-08-24T22:34:02.150

Reputation: 8 350

It sounds like he did (or tried to do) this. – las3rjock – 2009-08-24T22:49:30.137

yes, las3rjock is right. I tried this & even if i was failure.

Look at my Solution. I got the idea. – Sagar R. Kothari – 2009-08-24T22:50:42.210

P.S. @jtbandes I would give you another +1 if I could for mentioning TextMate. It's probably the most used application on my Mac, since I use it for editing everything. – las3rjock – 2009-08-24T22:58:30.743

@las3rjock: I only use Xcode for Cocoa stuff, but TextMate for everything else. I love it for web development. – jtbandes – 2009-08-24T22:59:37.217

2

Looking at the file formats in the "File->Save As..." dialog box in TextEdit, it seems that plain text is not among them. The default is Rich Text Format (hence the \rtf command codes in your file), and the other formats (in broad categories) are HTML, OpenDocument, and Word. You should probably use a plain-text format text editor such as TextWrangler to create and edit files like this.

EDIT: Plain-text formats do appear after you select "Format->Make Plain Text", but that still doesn't explain how sagar ended up with RTF when he tried to save in UTF-8 format.

las3rjock

Posted 2009-08-24T22:34:02.150

Reputation: 1 434

Actually I don't have any permission to download any extra software & install them. Is there any inbuilt editor available like text editor? – Sagar R. Kothari – 2009-08-24T22:42:41.430

3You could open up a Terminal window; start a command-line editor like pico, emacs, or vi; and type or paste in the contents of your plain-text file. – las3rjock – 2009-08-24T22:46:29.597

0

Open XCode.

Go to File Menu

->Select New File.

->Go to Other Option

->select Property list

->Give file name with xml extension.

-> enter your xml data & save.

Sagar R. Kothari

Posted 2009-08-24T22:34:02.150

Reputation: 4 267

2

Xcode works, but you should have no problem with TextEdit. You can enter the "xml" extension and it works fine. http://screencast.com/t/i0FsO7e5eS

– jtbandes – 2009-08-24T22:57:33.117