xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Monica Granbois" <mgranb...@abebooks.com>
Subject RE: changing the schemaLocation
Date Thu, 15 Jul 2004 18:07:29 GMT
Hi,

Thank you for your reply.  I tried the code, but it would insert the
attribute into my first element.  I tried using c.toStartDoc and
c.toFirstAttribute instead of c.toFirstChild(), but I was unable to set the
attribute value.  

I did the following, which seems to do the trick.

XmlObject x = XmlObject.Factory.parse( ... ); // Parse in your XML
XmlCursor c = x.newCursor(); // Cursor on the documentc.toStartDoc();
c.toFirstAttribute();
c.removeXml();
c.insertAttributeWithValue("schemaLocation",
"http://www.w3.org/2001/XMLSchema-instance", "http://www.foobar.com/XMLSchema
"+ "http://www.foobar.com/docs/Schemas/TheNewSchema.xsd");
c.dispose();

Thanks,

Monica

-----Original Message-----
From: Eric Vasilik [mailto:ericvas@bea.com] 
Sent: Wednesday, July 14, 2004 8:37 PM
To: xmlbeans-user@xml.apache.org
Subject: RE: changing the schemaLocation

Something like the following should work:

    XmlObject x = XmlObject.Factory.parse( ... ); // Parse in your XML
    XmlCursor c = x.newCursor(); // Cursor on the document

    c.toFirstChild();  // Navigate to document element

    c.setAttributeText(  // Change the attr value
        new QName(
           "http://www.w3.org/2001/XMLSchema-instance ",
          "schemaLocation" ),
       "TheNewSchem.xsd" );

    c.dispose();  // Done with the cursor

-Eric

-----Original Message-----
From: Monica Granbois [mailto:mgranbois@abebooks.com] 
Sent: Wednesday, July 14, 2004 7:35 PM
To: xmlbeans-user@xml.apache.org
Subject: changing the schemaLocation

Hi,

I have an xml document which I have parsed into my XmlObject.  I want to
change the schemaLocation that is reference by the xml.  Is there a way
to do
this?

For example if the xml had a schema location of original.xsd as below:

<xs:Foo xs:id="123" xs:deletestatus="false" xs:typecode="1"
xsi:schemaLocation="http://www.foobar.com/XMLSchema
http://www.foobar.com/docs/Schemas/original.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.foobar.com/XMLSchema">

Is it possible to change the schemaLocation to be 'TheNewSchema.xsd' as
shown
below:

<xs:Foo xs:id="123" xs:deletestatus="false" xs:typecode="1"
xsi:schemaLocation="http://www.foobar.com/XMLSchema
http://www.foobar.com/docs/Schemas/TheNewSchema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.foobar.com/XMLSchema">


I'm assuming I will need to use an XmlCursor, but I'm not sure if should
use
the execQuery() method to attempt this or not. Any pointers in which
direction I should be looking would be appreciated.

Thanks,

Monica


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


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


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


Mime
View raw message