Re: dtd question

2010-08-03 Thread Manfred Lotz
Hi Randy,

On Sun, 1 Aug 2010 15:02:59 -0700 (PDT)
Randy Hudson randy_hud...@mac.com wrote:

 I think we're almost there, sorry for the various mistakes.
 
 If you look in the source for clojure.xml, you can see that the
 default startparse argument for xml/parse is
 
 (defn startparse-sax [s ch]
   (.. SAXParserFactory (newInstance) (newSAXParser) (parse s ch)))
 
 and we've only gotten as far as the newSAXParser part with the
 definition of parser. So:
 
 (defn startparse [s ch] (.parse parser s ch))
 (defn parse-xml [source]  (xml/parse source startparse))
 

Indeed now it compiles. I also played with startparse but my mistake
was to omit the dot in front of parse.


For some reasons I do not get it to ignore the DTD but it seems (from
Google search) that others had that issue before with EntityResolver.
It looks like resolver gets ignored.



But I found this Java snippet: 
SAXParser parser = factory.newSAXParser();
parser.setFeature(http://apache.org/xml/features/nonvalidating/load-external-dtd;,
false); 


This is the code that works now:
(ns xmltest
  (:require [clojure.zip :as zip]
[clojure.xml :as xml])
  (:use clojure.contrib.zip-filter.xml))


(import
  '[javax.xml.parsers SAXParserFactory])

(def parser 
  (let [pf (SAXParserFactory/newInstance)]
(do (. pf setFeature
http://apache.org/xml/features/nonvalidating/load-external-dtd; false)
(.newSAXParser pf


(defn startparse [s ch] (.parse parser s ch))

(defn parse-xml [source]  (xml/parse source startparse))

(parse-xml (java.io.File. test.xml))




Thanks a lot for your help.


-- 
Manfred


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: dtd question

2010-08-01 Thread Manfred Lotz
Hi Randy,
Thanks for your help. A bit late my answer because in the meantime I was
on vacation and only now found the time to pursue it further.


On Tue, 29 Jun 2010 18:53:30 -0700 (PDT)
RandyHudson randy_hud...@mac.com wrote:

 Yes, you can do this by defining an EntityResolver that corrects the
 bad system id, define a SAXParser that uses that resolver, and pass
 the parser into the xml/parse call. Something like this:
 
 (import
   '[javax.xml.parsers SAXParserFactory]
   '[org.xml.sax EntityResolver InputSource])
 
 (def resolver
   (proxy [EntityResolver] []
 (resolveEntity [public-id system-id]
   (InputSource.
 (if (= system-id the-bad-system-id)
   the-good-system-id
   system-id)
 
 (def parser
   (doto (.newSAXParser (SAXParserFactory/newInstance))
 (.setEntityResolver resolver)))
 
 (defn parse-xml [source] (xml/parse source parser))
 
 

The problem I have with it is that I don't seem to find the right jar.
I get an exception like this:

Exception in thread main java.lang.IllegalArgumentException: No
matching method found: setEntityResolver for class
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl (test.clj:14)


I tried sax2r2.jar from http://www.saxproject.org/.





--  
Manfred


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: dtd question

2010-08-01 Thread Randy Hudson
Hi Manfred,

I'm sorry the code wasn't quite correct. The EntityResolver is set on
the parser's XMLReader, not on the parser itself:

(def parser (.newSAXParser (SAXParserFactory/newInstance))
(.setEntityResolver (.getXMLReader parser) resolver)

You don't need any external jars: all the classes and interfaces are
in the JRE.

On Aug 1, 5:31 am, Manfred Lotz manfred.l...@arcor.de wrote:
 Hi Randy,
 Thanks for your help. A bit late my answer because in the meantime I was
 on vacation and only now found the time to pursue it further.

 On Tue, 29 Jun 2010 18:53:30 -0700 (PDT)





 RandyHudson randy_hud...@mac.com wrote:
  Yes, you can do this by defining an EntityResolver that corrects the
  bad system id, define a SAXParser that uses that resolver, and pass
  the parser into the xml/parse call. Something like this:

  (import
    '[javax.xml.parsers SAXParserFactory]
    '[org.xml.sax EntityResolver InputSource])

  (def resolver
    (proxy [EntityResolver] []
      (resolveEntity [public-id system-id]
        (InputSource.
          (if (= system-id the-bad-system-id)
            the-good-system-id
            system-id)

  (def parser
    (doto (.newSAXParser (SAXParserFactory/newInstance))
      (.setEntityResolver resolver)))

  (defn parse-xml [source] (xml/parse source parser))

 The problem I have with it is that I don't seem to find the right jar.
 I get an exception like this:

 Exception in thread main java.lang.IllegalArgumentException: No
 matching method found: setEntityResolver for class
 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl (test.clj:14)

 I tried sax2r2.jar fromhttp://www.saxproject.org/.

 --  
 Manfred

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: dtd question

2010-08-01 Thread Manfred Lotz
Hi Randy,

On Sun, 1 Aug 2010 06:23:58 -0700 (PDT)
Randy Hudson randy_hud...@mac.com wrote:

 Hi Manfred,
 
 I'm sorry the code wasn't quite correct. The EntityResolver is set on
 the parser's XMLReader, not on the parser itself:
 
 (def parser (.newSAXParser (SAXParserFactory/newInstance))
 (.setEntityResolver (.getXMLReader parser) resolver)
 

It doesn't work. Even if I add a ) in the end I get
Exception in thread main java.lang.Exception: Too many arguments to
def (test.clj:21)

I tried then:

(def parser (doto (.newSAXParser (SAXParserFactory/newInstance))
(.setEntityResolver (.getXMLReader parser) resolver)))

which doesn't work either:
Exception in thread main java.lang.IllegalStateException: Var
xmltest/parser is unbound. (xmltest.clj:20)

I understand that parser after .getXMLReader cannot be resolved but I'm
unsure what has to be there.


-- 
Manfred



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: dtd question

2010-08-01 Thread Michael Wood
On 1 August 2010 17:15, Manfred Lotz manfred.l...@arcor.de wrote:
 Hi Randy,

 On Sun, 1 Aug 2010 06:23:58 -0700 (PDT)
 Randy Hudson randy_hud...@mac.com wrote:

 Hi Manfred,

 I'm sorry the code wasn't quite correct. The EntityResolver is set on
 the parser's XMLReader, not on the parser itself:

 (def parser (.newSAXParser (SAXParserFactory/newInstance))
 (.setEntityResolver (.getXMLReader parser) resolver)

 It doesn't work. Even if I add a ) in the end I get
 Exception in thread main java.lang.Exception: Too many arguments to
 def (test.clj:21)

 I tried then:

 (def parser (doto (.newSAXParser (SAXParserFactory/newInstance))
        (.setEntityResolver (.getXMLReader parser) resolver)))

I think he meant this:
(def parser (.newSAXParser (SAXParserFactory/newInstance)))
(.setEntityResolver (.getXMLReader parser) resolver)

-- 
Michael Wood esiot...@gmail.com

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: dtd question

2010-08-01 Thread Randy Hudson
Right you are Michael; sorry for the missing paren at the end of the
def.

On Aug 1, 11:59 am, Michael Wood esiot...@gmail.com wrote:
 On 1 August 2010 17:15, Manfred Lotz manfred.l...@arcor.de wrote:





  Hi Randy,

  On Sun, 1 Aug 2010 06:23:58 -0700 (PDT)
  Randy Hudson randy_hud...@mac.com wrote:

  Hi Manfred,

  I'm sorry the code wasn't quite correct. The EntityResolver is set on
  the parser's XMLReader, not on the parser itself:

  (def parser (.newSAXParser (SAXParserFactory/newInstance))
  (.setEntityResolver (.getXMLReader parser) resolver)

  It doesn't work. Even if I add a ) in the end I get
  Exception in thread main java.lang.Exception: Too many arguments to
  def (test.clj:21)

  I tried then:

  (def parser (doto (.newSAXParser (SAXParserFactory/newInstance))
         (.setEntityResolver (.getXMLReader parser) resolver)))

 I think he meant this:
 (def parser (.newSAXParser (SAXParserFactory/newInstance)))
 (.setEntityResolver (.getXMLReader parser) resolver)

 --
 Michael Wood esiot...@gmail.com

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: dtd question

2010-08-01 Thread Manfred Lotz
Hi Randy,


On Sun, 1 Aug 2010 10:04:16 -0700 (PDT)
Randy Hudson randy_hud...@mac.com wrote:

 Right you are Michael; sorry for the missing paren at the end of the
 def.
 

Now compiling the code works:

(def parser (.newSAXParser (SAXParserFactory/newInstance)))

(.setEntityResolver (.getXMLReader parser) resolver)

(defn parse-xml [source] (xml/parse source parser)) 



however when trying to apply it by adding 

(parse-xml (java.io.File. test.xml)) 


it no longer compiles: 
Exception in thread main java.lang.ClassCastException:
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl cannot be cast to
clojure.lang.IFn (xmltest1.clj:0)



 

-- 
Thanks,
Manfred


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: dtd question

2010-08-01 Thread Randy Hudson
I think we're almost there, sorry for the various mistakes.

If you look in the source for clojure.xml, you can see that the
default startparse argument for xml/parse is

(defn startparse-sax [s ch]
  (.. SAXParserFactory (newInstance) (newSAXParser) (parse s ch)))

and we've only gotten as far as the newSAXParser part with the
definition of parser. So:

(defn startparse [s ch] (.parse parser s ch))
(defn parse-xml [source]  (xml/parse source startparse))

should finally do it.

I do apologize, I'd forgotten about the function wrapper part of this
machinery. I hope this has been helpful despite my mistakes.


On Aug 1, 2:50 pm, Manfred Lotz manfred.l...@arcor.de wrote:
 Hi Randy,

 On Sun, 1 Aug 2010 10:04:16 -0700 (PDT)

 Randy Hudson randy_hud...@mac.com wrote:
  Right you are Michael; sorry for the missing paren at the end of the
  def.

 Now compiling the code works:

 (def parser (.newSAXParser (SAXParserFactory/newInstance)))

 (.setEntityResolver (.getXMLReader parser) resolver)

 (defn parse-xml [source] (xml/parse source parser))

 however when trying to apply it by adding

 (parse-xml (java.io.File. test.xml))    

 it no longer compiles:
 Exception in thread main java.lang.ClassCastException:
 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl cannot be cast to
 clojure.lang.IFn (xmltest1.clj:0)

 --
 Thanks,
 Manfred

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


dtd question

2010-06-29 Thread Manfred Lotz
Hi there,
I got a directory tree of xml documents all having the same dtd.
However the dtd file is not where the DOCTYPE SYSTEM entry says it is.

Currently, xml/parse throws an exception that the dtd file will not be
found.

Is there a possibility to tell xml/parse about a different location
of that dtd file?



-- 
Thanks,
Manfred

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: dtd question

2010-06-29 Thread RandyHudson
Yes, you can do this by defining an EntityResolver that corrects the
bad system id, define a SAXParser that uses that resolver, and pass
the parser into the xml/parse call. Something like this:

(import
  '[javax.xml.parsers SAXParserFactory]
  '[org.xml.sax EntityResolver InputSource])

(def resolver
  (proxy [EntityResolver] []
(resolveEntity [public-id system-id]
  (InputSource.
(if (= system-id the-bad-system-id)
  the-good-system-id
  system-id)

(def parser
  (doto (.newSAXParser (SAXParserFactory/newInstance))
(.setEntityResolver resolver)))

(defn parse-xml [source] (xml/parse source parser))



On Jun 29, 8:18 pm, Manfred Lotz manfred.l...@arcor.de wrote:
 Hi there,
 I got a directory tree of xml documents all having the same dtd.
 However the dtd file is not where the DOCTYPE SYSTEM entry says it is.

 Currently, xml/parse throws an exception that the dtd file will not be
 found.

 Is there a possibility to tell xml/parse about a different location
 of that dtd file?

 --
 Thanks,
 Manfred

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en