You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Upayavira <uv...@upaya.co.uk> on 2003/12/07 10:29:17 UTC

Parsing Source into DOM in Flow

Maybe my last question was too specific.

I'm trying to parse the contents of a source into a DOM in Flowscript, 
but am getting all sorts of errors. Can anyone provide a better way than 
this (which doesn't work)?

 var resolver = 
cocoon.getComponent(Packages.org.apache.excalibur.source.SourceResolver.ROLE); 

 var source = resolver.resolveURI("blah.xml");
 var builder = 
Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder(); 

 var is = source.getInputStream();
 var dom = builder.parse(source.getInputStream());

Regards, Upayavira



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Parsing Source into DOM in Flow

Posted by Andrew Savory <an...@luminas.co.uk>.
Hi,

On 9 Dec 2003, at 09:06, Upayavira wrote:

> xmldb:xindice-embed:///db/tuneballoon/music/#// 
> music[filename='Fathers']

> I'm now just stuck with what seems the limited XPath available to  
> Xindice (no 'contains' method).

Odd. Is this a change in Xindice 1.1? I've used XPaths like that in 1.0  
with no problems, eg:
	'/files/file[contains(metadata/title/string_value,"Ford")]'


Andrew.

--
Andrew Savory, Managing Director, Luminas Limited
Tel: +44 (0)870 741 6658  Fax: +44 (0)700 598 1135
Web: http://www.luminas.co.uk/
Orixo alliance: http://www.orixo.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Parsing Source into DOM in Flow

Posted by Upayavira <uv...@upaya.co.uk>.
With a clearer head, I now see that the errors were within the 
XMLDBSource code, and changing the XMLDB URL worked around the problem.

The problem as it now stands is that, when I use an XMLDB URI such as:

xmldb:xindice-embed:///db/tuneballoon/music/#//music[filename='Fathers']

I get a org.xmldb.api.base.XMLDBException.

Looking into this further, I see that it is due to Xerces 2.6. Without 
it in my classpath, it works fine.

I'm now just stuck with what seems the limited XPath available to 
Xindice (no 'contains' method).

Regards and thanks, Upayavira

Caused by: org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

	at org.apache.xml.utils.DOMBuilder.startElement(DOMBuilder.java:354)

	at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1073)

	at org.apache.cocoon.xml.AbstractXMLPipe.startElement(AbstractXMLPipe.java:130)

	at org.apache.cocoon.xml.IncludeXMLConsumer.startElement(IncludeXMLConsumer.java:181)

	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)

	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)

	at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)

	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)

	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)

	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)

	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

	at org.apache.xindice.client.xmldb.resources.XMLResourceImpl.getContentAsSAX(XMLResourceImpl.java:413)

	at org.apache.cocoon.components.source.impl.XMLDBSource.queryToSAX(XMLDBSource.java:354)

	at org.apache.cocoon.components.source.impl.XMLDBSource.collectionToSAX(XMLDBSource.java:258)

	at org.apache.cocoon.components.source.impl.XMLDBSource.toSAX(XMLDBSource.java:185)

	at org.apache.cocoon.components.source.SourceUtil.toSAX(SourceUtil.java:163)

	at org.apache.cocoon.components.source.SourceUtil.toSAX(SourceUtil.java:128)

	at org.apache.cocoon.components.source.SourceUtil.toDOM(SourceUtil.java:322)

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

	at java.lang.reflect.Method.invoke(Method.java:324)

	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:230)

	at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1244)



Thanks for your help. Upayavira

Christopher Oliver wrote:

> What errors did you get?
>
> Upayavira wrote:
>
>> Maybe my last question was too specific.
>>
>> I'm trying to parse the contents of a source into a DOM in 
>> Flowscript, but am getting all sorts of errors. Can anyone provide a 
>> better way than this (which doesn't work)?
>>
>> var resolver = 
>> cocoon.getComponent(Packages.org.apache.excalibur.source.SourceResolver.ROLE); 
>>
>> var source = resolver.resolveURI("blah.xml");
>> var builder = 
>> Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
>>
>> var is = source.getInputStream();
>> var dom = builder.parse(source.getInputStream());
>>
>> Regards, Upayavira
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Parsing Source into DOM in Flow

Posted by Christopher Oliver <re...@verizon.net>.
What errors did you get?

Upayavira wrote:

> Maybe my last question was too specific.
>
> I'm trying to parse the contents of a source into a DOM in Flowscript, 
> but am getting all sorts of errors. Can anyone provide a better way 
> than this (which doesn't work)?
>
> var resolver = 
> cocoon.getComponent(Packages.org.apache.excalibur.source.SourceResolver.ROLE); 
>
> var source = resolver.resolveURI("blah.xml");
> var builder = 
> Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
>
> var is = source.getInputStream();
> var dom = builder.parse(source.getInputStream());
>
> Regards, Upayavira
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Parsing Source into DOM in Flow

Posted by Guido Casper <gc...@s-und-n.de>.
Upayavira wrote:
> Maybe my last question was too specific.
>
> I'm trying to parse the contents of a source into a DOM in Flowscript,
> but am getting all sorts of errors. Can anyone provide a better way
> than this (which doesn't work)?
>
>  var resolver =
>
cocoon.getComponent(Packages.org.apache.excalibur.source.SourceResolver.
ROLE);
>
>  var source = resolver.resolveURI("blah.xml");
>  var builder =
>
Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocum
entBuilder();
>
>  var is = source.getInputStream();
>  var dom = builder.parse(source.getInputStream());

Sorry, I have no idea why that doesn't work. I just use

var dom =
Packages.org.apache.cocoon.components.source.SourceUtil.toDOM(source);

HTH
Guido




>
> Regards, Upayavira
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Parsing Source into DOM in Flow

Posted by Christopher Oliver <re...@verizon.net>.
Geoff Howard wrote:

> Upayavira wrote:
>
>> Maybe my last question was too specific.
>>
>> I'm trying to parse the contents of a source into a DOM in 
>> Flowscript, but am getting all sorts of errors. Can anyone provide a 
>> better way than this (which doesn't work)?
>>
>> var resolver = 
>> cocoon.getComponent(Packages.org.apache.excalibur.source.SourceResolver.ROLE); 
>>
>> var source = resolver.resolveURI("blah.xml");
>> var builder = 
>> Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
>
>
>
> I think I have observed that you cannot use the returned result of a 
> java method call ( newInstance() ) as a java object in flow ( 
> .newDocumentBuilder() ).

If that doesn't work it's defnitely a bug. What error did you get?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Parsing Source into DOM in Flow

Posted by Geoff Howard <co...@leverageweb.com>.
Upayavira wrote:
> Maybe my last question was too specific.
> 
> I'm trying to parse the contents of a source into a DOM in Flowscript, 
> but am getting all sorts of errors. Can anyone provide a better way than 
> this (which doesn't work)?
> 
> var resolver = 
> cocoon.getComponent(Packages.org.apache.excalibur.source.SourceResolver.ROLE); 
> 
> var source = resolver.resolveURI("blah.xml");
> var builder = 
> Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder(); 

I think I have observed that you cannot use the returned result of a 
java method call ( newInstance() ) as a java object in flow ( 
.newDocumentBuilder() ).

The workaround I have found is to separate the calls:

var builderFactory = 
Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();

var builder = builderFactory.newDocumentBuilder();

I don't know if this is a bug or not, don't know if it's only when 
calling with Packages or not.  I also have not carefully confirmed this.

Finally, don't we have a convenience component to do this?

Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org