On 12/10/2007, Alex Wibowo <[EMAIL PROTECTED]> wrote:
> I'm using XML bean to read an XML string, and modify the namespace before
> saving it back as XML string.
>
> Say the xml that I have is:
>
> <ZFI>
>     ...
> </ZFI>
>
> and I already have an XML object that represent this xml. What I had to do
> is:
>
>         XmlCursor cursor = xmlObject.newCursor();
>         // Cursor at STARTDOC
>         cursor.toNextToken();
>         // Cursor at START
>         cursor.toNextToken();
>         // Cursor after START
>          cursor.insertAttribute("xmlns","http://www.namespace.com";);
>
> I tried to do (at the same line as cursor.insertAttribute) :
>
>         cursor.insertNamespace ("","http://www.namespace.com";);
>
> but it didnt work. i.e the XML string produced doesnt have the namespace. So
> instead of having:
>
> <ZFI xmlns=" http://www.namespace.com";>...
>
> it only has:
>
> <ZFI>...
>
> Is there any reason why this happened? What is the best way to insert the
> default namespace, if I only have access
> to the XMLObject (i.e. apart from specifying the namespace during the
> construction of XMLObject) ?

I don't XMLBeans well enough yet, but namespace nodes aren't
attributes so I doubt you could change the namespace using an
attribute method...

Have a look at setName(new QName("http://www.namespace.com";, "ZFI ", ""))

Alternatively, (and probably the way I would do this sort of task) is
to use XSLT - use an indentity transform with a special template that
matches ZFI.


cheers
-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to