Hi Alex,

This is really unfortunate, for reading in xml documents
there is  XmlOptions.setLoadSubstituteNamespaces()
but for output I can't found anything similar.

I posted this question some time ago, without response
http://www.nabble.com/change-namespace-of-generated-document-t4158083.html

Maarten (and not Marteen, Axel ;-)

On 10/15/07, Alex Wibowo <[EMAIL PROTECTED]> wrote:
> Hi Marteen,
>
>
> I havent found any 'good' solution to this yet. The best solution I have
> found so far, is to either:
>
> 1. Insert the attribute 'xmlns'. But as pointed by Andrew, we are inserting
> attribute with name 'xmlns', and not a namespace. This is fine for me,
> since I dont need the XmlObject after this modification (I just need to spit
> the result back as string). Example:
>
> -------------------------------------
> XmlCursor cursor = xmlObject.newCursor();
>  // Cursor at STARTDOC
>
> cursor.toNextToken();
> // Cursor at START
>
> cursor.toNextToken();
> // Cursor after START
>
> cursor.insertAttributeWithValue("xmlns","http://www.namespace.com ");
> -------------------------------------
>
>
>
> 2. Insert the QName (again, as suggested by Andrew). Example:
>
> -------------------------------------
>  XmlCursor cursor = xmlObject.newCursor();
>   // Cursor at STARTDOC
>
>  cursor.toNextToken();
>  // Cursor at START
>
> cursor.setName(new
> QName("http://www.namespace.com",cursor.getName().getLocalPart(),""));
>  -------------------------------------
>
>
> Let me know if you can find better solution!
>
>
>
> Thanks!
>
>
>
>
>
> On 10/15/07, Maarten Bosteels <[EMAIL PROTECTED]> wrote:
> > Alex, please let me know your solution since I am facing the same problem:
> I want to change
> > the namespaces of the generated xml documents.
> >
> > Maarten
> >
> >
> >
> > On 10/12/07, Andrew Welch <[EMAIL PROTECTED]> wrote:
> > > 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]
> > >
> > >
> >
> >
>
>
>
> --
> Best regards,
>
>
> WiB
> -------------------
> http://alexwibowo.blogspot.com

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

Reply via email to