Page 1 of 1

Format/Indent single line XML

Posted: Sun Mar 10, 2013 4:38 am
by tgochenour
I have an XML without any whitespace between tags. I'm expecting Format/Indent to insert line feeds between tags but I get this output instead:

Code: Select all

<dataset oid="opalobj-92" currentuser="20014" systemdate="2013-03-09"
disableCapture="true" skip_pkey="true"><transaction txdef="injury"
txtype="update" txseq="1" extid="_561049"><injr_id type="number"
length="0" nullable="n" pkey="y" pval="561049"
>561049</injr_id><zip_cd type="varchar2" length="15" nullable="y"
>02903</zip_cd><injr_loc_stt_othr_cntry type="varchar2" length="20"
nullable="y"/><injr_loc_text type="varchar2" length="60"
nullable="y"/><unusual_clm_typ_cd type="varchar2" length="15"
nullable="y"/><injr_src_cd type="varchar2" length="15" nullable="y"
If I search/replace all '><' with '> <' then format/indent works as expected.

SECOND ISSUE: This file comes from IE posted to a server (MIME text/xml) and saved to disk before launching oXygen. It has this doctype declaration which when loaded into oXygen appears as Chinese characters. Deleting the doctype declaration then has oXygen load the file as it appears above. I have yet to figure out why IE is generating a utf-16 encoding instead of a utf-8 encoding.

<?xml version="1.0" encoding="UTF-16"?>

Re: Format/Indent single line XML

Posted: Mon Mar 11, 2013 4:29 pm
by tgochenour
I handled second issue by suppressing doctype generation in IE transformNode with
<xsl:output omit-xml-declaration="yes"/>. Even after setting encoding="UTF-8" IE still
would output UTF-16.

Re: Format/Indent single line XML

Posted: Mon Mar 11, 2013 4:59 pm
by adrian
Hi,

Note that the Format and Indent from Oxygen is schema aware. This means that depending on the schema, it will decide if it is allowed to insert white spaces (spaces, tabs and line breaks) or not in the corresponding position. It only does this between elements if the added white space is insignificant for the schema.
I'm guessing that in your context the parent element dataset has mixed content (both elements and text) and that's why Format and Indent considers it shouldn't insert line breaks between neighboring tags.

If know what you're doing and want to turn the schema awareness off and blindly format it, you can do so in Options > Preferences, Editor > Format > XML, clear the option Schema aware format and indent.
I would recommend setting it back on afterwards.


I can't really comment on IE. It all depends on the version of IE and let's just say that various versions of IE have "issues". If possible, I would recommend to avoid opening the XML in IE and instead try to save it directly to disk (download it): right click on the link in IE and Save target as....

Regards,
Adrian