xerces-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henry Roeland" <henry.roel...@hccnet.nl>
Subject Re: Ignoring Whitespace
Date Fri, 13 Sep 2002 07:40:53 GMT
After loading your XML document process it aganst a XSLT Document that
contains the <xsl:strip-space elements="*" />

My DOM solution looks like this:
"
   private final static String xslStripWhitspaces = "<xsl:stylesheet
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"
xmlns=\"http://www.w3.org/TR/REC-html40\">"+
   "<xsl:output method = \"xml\" indent = \"yes\" omit-xml-declaration =
\"yes\"/><xsl:strip-space elements=\"*\" />"+
   "<xsl:template match=\"@*|*|text()|processing-instruction()\">"+
   "<xsl:copy><xsl:apply-templates
select=\"@*|*|text()|processing-instruction()\"
/></xsl:copy></xsl:template></xsl:stylesheet>";

   private static Templates stripWhitSpaceTemplate = null;
   private static Transformer stripper = null;
   static
   {
      try
      {
         stripWhitSpaceTemplate =
TransformerFactory.newInstance().newTemplates(
                  new StreamSource(new StringReader(xslStripWhitspaces)));
         stripper = stripWhitSpaceTemplate.newTransformer();
         stripper.setOutputProperty("encoding", "UTF-8");
      }
      catch ( Exception ignore ) {}
   }
"

My solutions means an extra parse/process but it is the only way I know...

Suc6,

Henry
----- Original Message -----
From: "Malia Zaheer" <mzaheer@technicacorp.com>
To: <xerces-j-user@xml.apache.org>
Sent: Thursday, September 12, 2002 5:26 PM
Subject: RE: Ignoring Whitespace


> You may want to search the mail archive for xerces for questions like
this:
>
> http://marc.theaimsgroup.com/?l=xerces-j-user&r=1&w=2
>
>
>
>
> -----Original Message-----
> From: Nickolay Kolev [mailto:nmk@gmx.li]
> Sent: Thursday, September 12, 2002 8:59 AM
> To: xerces-j-user@xml.apache.org
> Subject: Ignoring Whitespace
>
>
> Hi All,
>
> I am a first time poster.
>
> Could anyone please point me to (or give me) a tip on ignoring the
> whitespace in XML elements (tabs, newlines, etc.)... I am using JDK 1.4.
> 1 and SAX (do you say "I use SAX"??).
>
> I am trying to get the sum of the contents (just numerical data) of all
> elements in a file but get errors.
>
> If I write the file as one line (no tabs or newlines) if works without
> complaints.
>
> Also I would like to know how to isolate the case in which there will
> be elements containing data other than numerical. (For example: <num>
> elements will contain the numerical data, all others some other data).
> How do I get the contents of only the <num> tags?
>
> I have tried searching the Java documentation, and generally the net
> but had no luck so I thought I'd ask.
>
> Sorry if I am bothering you with too newbie questions!
>
> Many thanks in advance,
> nmk
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Mime
View raw message