xml-xmlbeans-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Vasilik" <eric...@bea.com>
Subject RE: Remove Namespace Attributes from Output
Date Tue, 15 Jun 2004 21:48:50 GMT
Yup ... this code will remove namespaces from your document.  Note,
however, that you are dramatically changing the nature of your instance.
The namespace of an element is as integral to the name (especially for
our Java binding) as the local part is.

One thing this code does not catch is the names of attributes, it only
deals with the names of elements.  To remedy this, simply change
"c.isStart()" to "c.isStart() || c.isAttr()".

- Eric

> -----Original Message-----
> From: Baer, David M [mailto:D1Bw@pge.com]
> Sent: Tuesday, June 15, 2004 2:43 PM
> To: xmlbeans-dev@xml.apache.org
> Subject: RE: Remove Namespace Attributes from Output
> 
> I've seen others ask this same question, and haven't seen an official
> recommendation.  However, below is some code that seems to do the
trick
> for me.  If you've got namespace-qualified attribute names, then
> additional massaging would be needed.
> 
> import com.bea.xml.XmlCursor;
> import com.bea.xml.XmlObject;
> import javax.xml.namespace.QName;
> . . .
> private void localizeXmlFragment(XmlObject x)
> {
>     String s;
>     XmlCursor c = x.newCursor();
>     c.toNextToken();
>     while (c.hasNextToken())
>     {
>         if (c.isNamespace())
>             c.removeXml();
>         else
>         {
>             if (c.isStart())
>             {
>                 s = c.getName().getLocalPart();
>                 c.setName(new QName(s));
>             }
>             c.toNextToken();
>         }
>     }
>     c.dispose();
> }
> 
> -----Original Message-----
> From: Poul.Elverum@perficient.com [mailto:Poul.Elverum@perficient.com]
> Sent: Tuesday, June 15, 2004 2:32 PM
> To: xmlbeans-dev@xml.apache.org
> Subject: Remove Namespace Attributes from Output
> 
> 
> Is there a recommended approach to removing the xmlns attribute from
the
> output produced by an XML schema using XMLBeans?  I have been able to
> successfully get it so my output doesn't include any namespace
prefixes to
> my elements, but certain elements still have xmlns attributes.
> Unfortunately, the consuming application for the output document does
not
> accept documents with the xmlns attribute, and therefore I must remove
it.
> I have been attempting to use the XMLCursor functionality to navigate
the
> document tree, but I have yet to be successful in getting this to
work.
> 
> Thanks,
> 
> Poul Elverum
> Technical Architect
> Perficient, Inc. - Minneapolis
> 100 N. 6th Street, Suite 935C
> Minneapolis, MN 55403
> D: 612.752.1575
> F: 612.524.2000
> E: poul.elverum@perficient.com
> 
> 
> 
> -
---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-dev-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
> 
> 
> -
---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-dev-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
> 


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-dev-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Mime
View raw message