Completely disable Pretty-Print

Having trouble installing Oxygen? Got a bug to report? Post it all here.
outshined
Posts: 2
Joined: Thu Jun 04, 2009 10:17 pm

Completely disable Pretty-Print

Post by outshined »

Is there a way to completely disable Pretty-Print?

I want to edit a XML styled with a CSS then import it in InDesign but when Oxygen reformat to Pretty-Print is doesn't import properly in InDesign.

Thanks!
Radu
Posts: 9051
Joined: Fri Jul 09, 2004 5:18 pm

Re: Completely disable Pretty-Print

Post by Radu »

Hi,

You are probably referring to the pretty-print which is done when the XML displayed in the Author page gets saved.
You can either set an "xml:space='preserve'" attribute on the XML root element or in the associated CSS file add a rule like:

Code: Select all


* {
white-space:pre;
}
Of course the rule can be more specific if you discover what elements need to be skipped from pretty-printing.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
outshined
Posts: 2
Joined: Thu Jun 04, 2009 10:17 pm

Re: Completely disable Pretty-Print

Post by outshined »

Thanks, glad it worked!
ra0543
Posts: 80
Joined: Wed Jan 14, 2009 12:50 pm

Re: Completely disable Pretty-Print

Post by ra0543 »

Can you give clear step-by-step instructions for what to do?

In particular, I want to be able to switch back and forth between Text and Author views without any spaces being added anywhere at all. I am happy for Oxygen to generate line breaks between elements of my choice when switching from Author to Text view, so long as these are then ignored for display purposes when I switch back to Author view; I have the line breaks in my Author view generated by my CSS as generated content at present because I don't want my authors inserting any punctuation or linebreaks (they can't be relied upon to be consistent in these).

I have tried using xml:space='preserve' as an attribute in the Schema for the document; it is valid there, but seems to have no effect whatsoever. I then tried it as an attribute of elements in the document itself, and it was rejected there as invalid. What am I supposed to do with it? Or doesn't it work? Or is there some other work round?

Why is something which causes so much mayhem in simple text files (it doubles the size of my files and introduces spaces within the text content of elements), viz. pretty-print, not able to be enabled/disabled by a simple option in Oxygen?

Any help on this totally baffling point (since the manual offers none, it seems) would be appreciated.
Radu
Posts: 9051
Joined: Fri Jul 09, 2004 5:18 pm

Re: Completely disable Pretty-Print

Post by Radu »

Hi,

You have 2 options:
1) Open the CSS used to render the XML file in Oxygen.
If you do not know where it is located, it is either associated with the XML via a processing instruction or it is associated via the document type used for the XML file.
In the CSS file for the elements for which you do not want indent or line breaks just add CSS rules like:

Code: Select all


element_name {
white-space:pre-wrap;
}

2) The xml:space='preserve' attribute specified on the root element of the XML file should work for what you need and no format and indent will be done when saving in the Author page.
If it is marked as invalid by the automatic validation then you can specify in the associated schema that the root element can accept "xml:space" as an attribute. Just add an import in the schema:

Code: Select all


<xs:import namespace="http://www.w3.org/XML/1998/namespace"/>
and then add an attribute reference on the root element like:

Code: Select all


<xs:attribute ref="xml:space"/>

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
ra0543
Posts: 80
Joined: Wed Jan 14, 2009 12:50 pm

Re: Completely disable Pretty-Print

Post by ra0543 »

OK. Thanks, I have now done both the things in (2) and it seems to work.

[In fact, I added

Code: Select all

<xs:attribute ref="xml:space" fixed="preserve" use="required"/>
not to the root but to relevant descendant elements, to allow some reformatting, i.e. inserting line breaks in helpful places, when switching to Text view and to ensure that Oxygen inserts the attribute automatically when adding a new relevant entity in Author view.]
ra0543
Posts: 80
Joined: Wed Jan 14, 2009 12:50 pm

Re: Completely disable Pretty-Print

Post by ra0543 »

My mistake - it only seemed to work. What in fact it did was to make the XML document valid against the Schema but then made the Schema itself invalid. The consequence of this seems to be that the XML document is not validated at all (hence no problems show up) because the Schema was unable to be validated. Here is the problematic part of the Schema:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xs:element name="rootelement">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="subelement"/>
</xs:sequence>
<xs:attribute ref="xml:space"/>
</xs:complexType>
</xs:element>
..

</xs:schema>
When validated, the <xs:attribute ..> is underlined in red and the error produced is the following:
E [Xerces] src-resolve: Cannot resolve the name 'xml:space' to a(n) 'attribute declaration' component.
and also
E [Xerces] s4s-elt-invalid-content.1: The content of '#AnonType_MLDFASC' is invalid. Element 'attribute' is invalid, misplaced, or occurs too often.
both referring to the relevant line.

Can you indicate the correct formulation of this fragment so that it validates OK?
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Completely disable Pretty-Print

Post by sorin_ristache »

For example the following is a valid XML Schema:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xs:element name="rootelement">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="subelement"/>
</xs:sequence>
<xs:attribute ref="xml:space"/>
</xs:complexType>
</xs:element>

<xs:element name="subelement" type="xs:string"/>
</xs:schema>
Do you get validation errors for this schema in Oxygen? What Oxygen version do you use?


Regards,
Sorin
Post Reply