This is a Xalan-J users forum. Your question seems to be related to,
how to use DOM API (with Xerces I guess). You should subscribe to
j-users@xerces.apache.org for that.

But I can try to answer your question.

If you have got a XML document wrapped in org.w3c.dom.Document, then
Document interface doesn't provide any method to do something like
doc.setVariable("foo", "bar"). I think XSLT will be more suitable for
this task. And you can use Xalan-J for that.

I think you have to traverse the DOM object, and reach to the
concerned text node (${foo} -- wrapped in org.w3c.dom.Node). Then you
can modify the value of this node.

On 4/4/07, Joona Palaste <[EMAIL PROTECTED]> wrote:
How can I set variables in an XML document in Java?
Suppose I have the following XML document in a file on disk:

<?xml version="1.0" encoding="UTF-8"?>
<document>
 <entity type="normal" id="1">${foo}</entity>
</document>

Then I use an org.w3c.dom.DocumentBuilder to parse this into an
org.w3c.dom.Document. Let's say I store this Document in the variable
doc. How can I do something like this:

doc.setVariable("foo", "bar");

so the document the Document represents ends up as this?

<?xml version="1.0" encoding="UTF-8"?>
<document>
 <entity type="normal" id="1">bar</entity>
</document>

Joona Palaste


--
Regards,
Mukul Gandhi

Reply via email to