You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Nicolas BONNEMORT <n....@akka.eu> on 2010/04/20 09:49:07 UTC

{Disarmed} Adding namespace to an xml file

Hi all.

First time using namespace with /XmlBeans/...

Our customer wants to add a namespace to its /xml /file... but in a 
"particular way".
_From_:
/<Root schemaVersion="1.1" >
<Elt1>
<Elt11>
<Elt111 Att1111="value1111" Att1112="value1112">
</Elt111>
</Elt11>
</Elt1>
<Elt2>
<Elt21 Att211="value211" Att212="value212">
     ...
</Elt21>
</Elt2>
</Root>
/_He wants_:
/<Root schemaVersion="1.1" *xsi:noNamespaceSchemaLocation="aSchema.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">*
<Elt1>
<Elt11>
<Elt111 Att1111="value1111" Att1112="value1112">
</Elt111>
</Elt11>
</Elt1>
<Elt2>
<Elt21 Att211="value211" *xsi:*Att212="value212">
     ...
</Elt21>
</Elt2>
</Root>
/*And no more changes.*

I found nothing in generated classes methods, but by using XmlCursor, I 
can do this:
/XmlCursor schemaCursor = myDoc.newCursor();
QName myQName = new QName("http://www.w3.org/2001/XMLSchema-instance", 
"noNamespaceSchemaLocation", "xsi");
if (schemaCursor.toFirstChild())
{
     schemaCursor.setAttributeText(myQName, 
prop.getProperty("SchemaLocation"));
}
schemaCursor.dispose();
/
It works fine... *but I cannot add the right prefix to the /Att212 
/attribute!*
_I tried_:

    * /aNewCursor.insertAttributeWithValue("Att212", "value212");/
    * /aNewCursor.insertAttributeWithValue("Att212",
      "http://www.w3.org/2001/XMLSchema-instance", "value212");/
    * /aNewCursor.insertAttributeWithValue("Att212", , "xsi", "value212");/
    * /aNewCursor.insertAttributeWithValue("noNamespaceSchemaLocation"
      ,"http://www.w3.org/2001/XMLSchema-instance",
      prop.getProperty("SchemaLocation"));
      aNewCursor.insertAttributeWithValue("Att212", "value212");
      aNewCursor.insertNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance")./


But it does not work.
I think I do not understand correctly the documentation (sorry, I am 
french! ;-) ) or forget something somewhere... but even after a good 
night (well, kind of...), I cannot find what.

Can you help me please?

Thanks,

-- 
Nicolas BONNEMORT
Akka Informatique Et Systemes
ASTEI
+33 (0)5.34.60.81.65