You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Greg Matthews <gm...@flex.com.au> on 2001/02/15 04:24:50 UTC

carriage return in attribute not preserved

dear all,

how do i preserve carriage returns inside attributes?

if i have some xml as a String,

<x a="hello
world"/>

then when i parse it and then serialize it like follows the carriage return is lost, and i end up with

<x a="hello world"/>

  org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser();
  InputSource is = new InputSource( new ByteArrayInputStream( s.getBytes()));
  parser.parse( is );
  Element n2 = parser.getDocument().getDocumentElement();
  OutputFormat of = new OutputFormat();
  of.setOmitXMLDeclaration( true );
  of.setIndenting( false );
  org.apache.xml.serialize.XMLSerializer ser = new XMLSerializer( System.out, of );
  ser.asDocumentHandler();
  ser.setOutputFormat( of );
  ser.serialize( n2 );

what do i need to do to keep the original format?

thanks,
greg.

Re: carriage return in attribute not preserved

Posted by Greg Matthews <gm...@flex.com.au>.
sam and tom, thanks for the response.

i think we're just going to do a URLEncoder.encode() + 
URLEncoder.decode() at each end so we get back
attributes with carriage returns.


----- Original Message ----- 
From: "Tom Bradford" <br...@dbxmlgroup.com>
To: <xe...@xml.apache.org>
Sent: Friday, February 16, 2001 5:34 AM
Subject: Re: carriage return in attribute not preserved


> > Sam Pullara wrote:
> > The conversion of a LF to a space in attribute values is actually in
> > the specification. See XML 1.0.
> 
> Continuing on that, you can probably define an entity that stores the
> carriage return, and embed it into the attribute:
> 
>    hello&cr;world
> 
> Attributes values are supposed to respect mixed content that includes
> text and entity references.  I'm almost 100% sure Xerces supports this.
> 
> -- Tom
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 


Re: carriage return in attribute not preserved

Posted by Tom Bradford <br...@dbxmlgroup.com>.
> Sam Pullara wrote:
> The conversion of a LF to a space in attribute values is actually in
> the specification. See XML 1.0.

Continuing on that, you can probably define an entity that stores the
carriage return, and embed it into the attribute:

   hello&cr;world

Attributes values are supposed to respect mixed content that includes
text and entity references.  I'm almost 100% sure Xerces supports this.

-- Tom

RE: carriage return in attribute not preserved

Posted by Sam Pullara <sa...@sampullara.com>.
The conversion of a LF to a space in attribute values is actually in the
specification. See XML 1.0.

Sam
  -----Original Message-----
  From: Greg Matthews [mailto:gmatthews@flex.com.au]
  Sent: Wednesday, February 14, 2001 7:25 PM
  To: xerces-j-user@xml.apache.org
  Subject: carriage return in attribute not preserved



  dear all,

  how do i preserve carriage returns inside attributes?

  if i have some xml as a String,

  <x a="hello
  world"/>

  then when i parse it and then serialize it like follows the carriage
return is lost, and i end up with

  <x a="hello world"/>

    org.apache.xerces.parsers.DOMParser parser = new
org.apache.xerces.parsers.DOMParser();
    InputSource is = new InputSource( new ByteArrayInputStream(
s.getBytes()));
    parser.parse( is );
    Element n2 = parser.getDocument().getDocumentElement();
    OutputFormat of = new OutputFormat();
    of.setOmitXMLDeclaration( true );
    of.setIndenting( false );
    org.apache.xml.serialize.XMLSerializer ser = new XMLSerializer(
System.out, of );
    ser.asDocumentHandler();
    ser.setOutputFormat( of );
    ser.serialize( n2 );

  what do i need to do to keep the original format?

  thanks,
  greg.

RE: Windows Paths

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
I must still be missing something. Neither

parser.parse("c:/test/data.xml");

or

parser.parse("file://c:/test/data.xml");

are working.  They are both causing a NullPointerException to be thrown,
same as the "c:\test\data.xml" string below.

Any other ideas, or have I missed something?

Brad

-----Original Message-----
From: Milind Gadre [mailto:milind@ecplatforms.com]
Sent: Monday, February 19, 2001 12:56 PM
To: xerces-j-user@xml.apache.org
Subject: Re: Windows Paths


Brad, use forward slashes ... c:/a/b/c

Regards...

Milind Gadre
ecPlatforms, Inc
901 Mariner's Island Blvd, Suite 565
San Mateo, CA 94404
C: 510-919-0596
F: 815-352-0779
milind@ecplatforms.com

>
> parser.parse("c:\test\data.xml");
>



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


Re: Windows Paths

Posted by Milind Gadre <mi...@ecplatforms.com>.
Brad, use forward slashes ... c:/a/b/c

Regards...

Milind Gadre
ecPlatforms, Inc
901 Mariner's Island Blvd, Suite 565
San Mateo, CA 94404
C: 510-919-0596
F: 815-352-0779
milind@ecplatforms.com

> 
> parser.parse("c:\test\data.xml");
> 



Windows Paths

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
Hello all...

I am trying to figure out what the proper format is to specify an absolute
path on a Windows platform as the URI for the parse method.  If I have an
XMLReader called parser, the following:

parser.parse("c:\test\data.xml");

will not work.  I am finding this same issue a bit of an problem when trying
to resolve the dtd in the EntityResolver as well, since the resolveEntity
method is receiving a systemId that includes path info, as in
file:///test/dtd/data.dtd.  Specifically, on a Windows platform, how do you
include the drive letter in the URI?

Thanks in advance.

Brad


Re: NullPointerException trying to parse a simple XML file.

Posted by Elena Litani <hl...@jtcsv.com>.
Hi, Brad,
It is hard to say what is going on without any additional info. I
suspect you have some error in your code, cause I don't recall anybody
reporting this kind of behaviour before.
If you still need help, please, attach your .java files + sample file.

Thank you,
Elena

> Brad O'Hearne wrote:
> 
> This should be a pretty simple question.  Running the following code:
> 
> 
>     try {
>       XMLReader parser =
> XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
>       parser.setContentHandler(contentHandler);
>       parser.setErrorHandler(errorHandler);
>       parser.setEntityResolver(new FeedEntityResolver(dtdPath));
>       parser.setFeature("http://xml.org/sax/features/validation",
> true);
>       try {
>         parser.parse(uri);
>       }
>       catch (IOException e) {
>         throw new FeedException("IOException, error reading URI: " +
> e.getMessage(), e);
>       }
>       catch (SAXException e) {
>         e.printStackTrace();
>         throw new FeedException("Error in parsing: " + e.getMessage(),
> e);
>       }
>     }
>     catch (SAXException e) {
>       throw new FeedException("Unable to create parser.", e);
>     }
> where
> contentHandler is a valid ContentHandler
> errorHandler is a valid ErrorHandler
> FeedEntityResolver is a valid Entity Resolver
> uri is a valid absolute filename.
> 
> I am having the following Exception thrown:
> 
> java.lang.NullPointerException
>  at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:878)
>  at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:900)
> 
> No methods on my ErrorHandler, ContentHandler, or EntityResolver are
> ever getting called.  Does anyone have any idea what I am missing?
> The problem seems to be contained within the parser code....
> 
> Any help is greatly appreciated.
> 
> Brad

RE: NullPointerException trying to parse a simple XML file.

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
One correction....the fatalError method on my ErrorHandler is getting
called....but there isn't much detail, just what is below...any ideas?

Brad
  -----Original Message-----
  From: Brad O'Hearne [mailto:cabodog@megapathdsl.net]
  Sent: Wednesday, February 14, 2001 6:53 PM
  To: xerces-j-user@xml.apache.org
  Subject: NullPointerException trying to parse a simple XML file.


  This should be a pretty simple question.  Running the following code:


      try {
        XMLReader parser =
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
        parser.setContentHandler(contentHandler);
        parser.setErrorHandler(errorHandler);
        parser.setEntityResolver(new FeedEntityResolver(dtdPath));
        parser.setFeature("http://xml.org/sax/features/validation", true);
        try {
          parser.parse(uri);
        }
        catch (IOException e) {
          throw new FeedException("IOException, error reading URI: " +
e.getMessage(), e);
        }
        catch (SAXException e) {
          e.printStackTrace();
          throw new FeedException("Error in parsing: " + e.getMessage(), e);
        }
      }
      catch (SAXException e) {
        throw new FeedException("Unable to create parser.", e);
      }

  where
  contentHandler is a valid ContentHandler
  errorHandler is a valid ErrorHandler
  FeedEntityResolver is a valid Entity Resolver
  uri is a valid absolute filename.

  I am having the following Exception thrown:

  java.lang.NullPointerException
   at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:878)
   at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:900)

  No methods on my ErrorHandler, ContentHandler, or EntityResolver are ever
getting called.  Does anyone have any idea what I am missing?  The problem
seems to be contained within the parser code....

  Any help is greatly appreciated.

  Brad

NullPointerException trying to parse a simple XML file.

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
This should be a pretty simple question.  Running the following code:


    try {
      XMLReader parser =
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
      parser.setContentHandler(contentHandler);
      parser.setErrorHandler(errorHandler);
      parser.setEntityResolver(new FeedEntityResolver(dtdPath));
      parser.setFeature("http://xml.org/sax/features/validation", true);
      try {
        parser.parse(uri);
      }
      catch (IOException e) {
        throw new FeedException("IOException, error reading URI: " +
e.getMessage(), e);
      }
      catch (SAXException e) {
        e.printStackTrace();
        throw new FeedException("Error in parsing: " + e.getMessage(), e);
      }
    }
    catch (SAXException e) {
      throw new FeedException("Unable to create parser.", e);
    }

where
contentHandler is a valid ContentHandler
errorHandler is a valid ErrorHandler
FeedEntityResolver is a valid Entity Resolver
uri is a valid absolute filename.

I am having the following Exception thrown:

java.lang.NullPointerException
 at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:878)
 at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:900)

No methods on my ErrorHandler, ContentHandler, or EntityResolver are ever
getting called.  Does anyone have any idea what I am missing?  The problem
seems to be contained within the parser code....

Any help is greatly appreciated.

Brad