Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

myitrumors

macrumors newbie
Original poster
Nov 18, 2019
24
1
I downloaded several pre-made configuration profiles (xml) but when I use Xcode to edit each of them, the indentation formatting for each keys, string, integer, elements, etc came in one single line. I am talking about the entire document. Example:

<dict><key>OfficeAutoSignIn</key><true/><key>ShowWhatsNewOnLaunch</key><false/><key>DefaultsToLocalOpenSave</key><true/></dict></dict></array></dict></dict></dict><dict><key>PayloadUUID</key><string>1A314508-09FV-40C6-80F4-B98AAQWEC8D</string><key>PayloadType</key><string>com.apple.ManagedClient.preferences</string><key>PayloadOrganization</key><string>XYZ</string><key>PayloadIdentifier</key><string>CD2345508-40F3-40C6-80F4-TY7WSDDAC8D</string><key>PayloadDisplayName</key><string>Custom</string><key>PayloadDescription</key><string/><key>PayloadVersion</key><integer>1</integer><key>PayloadEnabled</key><true/><key>PayloadContent</key><dict><key>com.microsoft.Office365ServiceV2</key><dict><key>Forced</key><array><dict><key>mcx_preference_settings</key><dict><key>SendAllTelemetryEnabled</key><true/></dict></dict></array></dict></dict></dict><dict><key>PayloadUUID</key><string>NMJK78543-42EE-41F7-97D7-765CC1832E08</string><key>PayloadType</key><string>com.apple.ManagedClien....etc...etc.

Of course, I can place the mouse cursor at the end of each element and press return and Xcode will automatically fix the indentation in the correct way, but it will take me for ever to do this for each files.


I was wondering, in Xcode, by doing Select All (select the entire code of the xml file), there is any option that magically will put the entire code in the correct indentation format with all the correct tab spaces?
 

casperes1996

macrumors 604
Jan 26, 2014
7,593
5,764
Horsens, Denmark
I mean Xcode does have an option called "re-indent" or something like that (I usually just hit the Help button and write "indent" and it's the first option) - but I'm not sure it will work if it's all one line.
Instead I'd use Find and Replace. - Now I can't remember if Xcode supports regular expressions, but otherwise open the file in IntelliJ, enable regular expressions for Find and Replace, and write something like
<key>
and replace with
\n<key>

Then open the file in Xcode again ant then use the aforementioned indentation function
 

joevt

macrumors 604
Jun 21, 2012
6,935
4,237
If it's a plist, then this:
plutil -convert xml1 input.plist -o formatted.plist
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.