velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike J Boyersmith <mjboy...@us.ibm.com>
Subject JDOM and NOT using anakia ant task
Date Tue, 18 Jan 2005 18:40:23 GMT
Its my understanding that if I want to use Anakia it needs to be ran from 
an ant build script?
so...... I want to execute a template against a loaded JDOM. like the 
following:

SAXBuilder builder;
Document root = null;
builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser" );
root = builder.build( XMLFile );
 
//Stuff the Document (or root Element) into the context:
VelocityContext context = new VelocityContext();
context.put("root", root );

/* write to file */
BufferedWriter writer = writer = new BufferedWriter(
new FileWriter("./output/StartPage.html"));

if ( template != null)
   template.merge(context, writer);


BUT I am not having a whole lot of luck with it parsing my DOM correctly. 
I can dump my JDOM and it shows the tree correctly. 
but I am having problems doing simple things like getting at elements. 
heres an example

I have the following data

<?xml version="1.0" encoding="UTF-8"?>
<publish:project name="Published Items" xmlns:publish="http://a/b/c">
  publish project
<foo>
this is foo
</foo>
<publish:link>
 publish link 1
</publish:link>
<publish:link>
 publish link 2
</publish:link>
</publish:project>

I'm TRYING to get output text for <publish:link> but no matter what I try 
I can't seem to get
the element. sigh...... I suspect I'm running into a namespace problem. If 
I try to fetch <foo> it works, but
if I try to fetch <publish:link> it doesn't. Any ideas?????


Heres what I have tried in my script file(note the r, s, t, u, a , b, c , 
d is just to identify my output easier)

<html>
...
    <body>
-------------see what kinds of URI, or prefixes we can fetch 
---------------<br>
r $root.getPrefix()<br>
s $root.getRootElement().getPrefix()<br>
t $root.getNamespaceURI()<br>
u $root.getRootElement().getNamespaceURI() //Works: RETURNS http://a/b/c

------ now try to get stuff --- <br>

a $root.getRootElement().getChild("foo").getText()<br>  //WORKS: returns 
text of foo element

------------ Everything from here on FAILS to do anything <br>
------------ (I got to the point of trying everything I could think 
of..and nadda working)<br>

b $root.getRootElement().getChild("publish:project", 
"http://a/b/c").getText()<br>
c $root.getRootElement().getChild("publish:project", 
"http://a/b/c").getText()<br>
d $root.getRootElement().getChild("project", "http://a/b/c").getText()<br>
e $root.getRootElement().getChild("project").getText()<br> 
f $root.getRootElement().getChild("publish:link").getText()<br>
g $root.getRootElement().getChild("link", "http://a/b/c" ).getText()<br>
h $root.getRootElement().getChild("publish:link", "http://a/b/c" 
).getText()<br>
i $root.getRootElement().getChild("link", "publish").getText()<br>
j $root.getRootElement().getChild("publish:link", "publish").getText()<br>
k $root.getRootElement().getChild("link").getText()<br> 

--------------------Try to get from getChild() directly  -------<br>
l $root.getChild("publish:link").getText()<br>
m $root.getChild("link", "http://a/b/c" ).getText()<br>
n $root.getChild("publish:link", "http://a/b/c" ).getText()<br>
o $root.getChild("link", "publish").getText()<br>
p $root.getChild("publish:link", "publish").getText()<br>
q $root.getChild("link").getText()<br>

    </body>
</html>



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message