xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lance Robertson <lance.robert...@jda.com>
Subject RE: Removing the Namespace from each Tag
Date Fri, 09 Jan 2004 21:29:02 GMT
Really I don't even want the namespace stuff in there at all if I could do
without it. I would really like
But with XMLBeans when i'm doing the schema it makes me put the namespace in
as if I don't it puts it in noNameSpace for the package. 
I also have "global" element "Associate" that is used in another part of the
XML over and over so that complicates things as well. 
So this generate correctly, 
<xs:schema targetNamespace=" <http://company.com/> http://company.com/"
xmlns:xs=" <http://www.w3.org/2001/XMLSchema>
http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"

This does not.
<xs:schema xmlns:xs=" <http://www.w3.org/2001/XMLSchema>
http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"

I'm still new to XML stuff so I'm possibly erroring somewhere or not
thinking about it in the correct way. Thanks for any input you might have.
-----Original Message-----
From: Toby H Ferguson [mailto:toby.h.ferguson@Sun.COM] 
Sent: Friday, January 09, 2004 1:27 PM
To: xmlbeans-user@xml.apache.org
Subject: Re: Removing the Namespace from each Tag

Is your second example valid XML? I think not because you've that the
Timeslips element is in the namespace http://company.com
<http://company.com> , which is to be represented by the prefix "company",
but then you've not used the prefix. I think you should use the empty prefix
namespace construct thus:
<Timeslips xmlns="http//company.com">

But this has nothing to do with XMLBeans of course (except inasmuch as
XMLBeans cares about well-formed XML)

Toby Ferguson

Lance Robertson wrote:

Ok, so if my xml looks like this:

<company:Timeslips xmlns:company=" <http://company.com> http://company.com">

and I want it to look like this:
<Timeslips xmlns:company="http://company.com <http://company.com> ">

I would have to go through each of the elements and remove the "company:"
from it?
Thanks again for your help
  -----Original Message-----
From: Eric Vasilik [mailto:ericvas@bea.com <mailto:ericvas@bea.com> ] 
Sent: Friday, January 09, 2004 10:50 AM
To: xmlbeans-user@xml.apache.org <mailto:xmlbeans-user@xml.apache.org> 
Subject: RE: Removing the Namespace from each Tag

Do you want the elements saved out to not have any namespace associated with
them at all, or do you simply want to use the default namespace for all of
your elements?  If it is the former and you are currently seeing prefixes
prepended to your tag names, then you will need to remove the namespace from
all the pertinent elements (you can use set/getName on XmlCursor to do
this).  Or, if you simply want to make sure the default namespace is used to
distribute a namespace to all your elements, then you can use the
XmlOptions: setSaveAggresiveNamspaces and setUseDefaultNamespace.

Basically, elements either have or have no namespace in their name, and the
saver guarantees that the saved XML reflects these namespace associations.
It will do this by synthesizing or removing namespace attributes and
prefixes for various elements.  The two options I mention above adjust how
the saver will achieve this goal.

- Eric

-----Original Message-----
From: Lance Robertson [mailto:lance.robertson@jda.com
<mailto:lance.robertson@jda.com> ] 
Sent: Friday, January 09, 2004 7:56 AM
To: 'xmlbeans-user@xml.apache.org <mailto:xmlbeans-user@xml.apache.org> '
Subject: Removing the Namespace from each Tag

I'm new to XML beans and we are investigating it for use in our program.
However I've run across something that I need to remove from the output XML
before we can use it. When we generate XML using the XMLBeans the namespace
is added to each tag <ns1:tagname>. We need to not have the ns1: in the tag.
Is there a way to do this? I've looked through the mailing list and found
what I thought might have been a solution, however when I tried it it did
not work.

Is there a way for the namespace not to be added to each tag? Thank you in

Solution Tried:

   HashMap suggestedPrefixes = new HashMap();
  suggestedPrefixes.put(" <http://company.com> http://company.com", "");
  XmlOptions opts = new XmlOptions();
  opts.setSaveSuggestedPrefixes(suggestedPrefixes); <---Tried this first
  opts.setUseDefaultNamespace();  <--- Tried this second

   newTimeslipsDoc.save(new File("TimeslipSample2.xml"), opts);
  catch (Exception e)
   System.out.println("Couldn't write file");


View raw message