One more thing. You should navigate to between the START and END tokens of the element to which you wish to add the attribute when you call insertAttributeWithValue(). More detail on this can be found at http://xmlbeans.apache.org/docs/2.0.0/guide/conNavigatingXMLwithCursors.html.

 

Cheers,

 

Lawrence

 


From: Lawrence Jones
Sent: Friday, August 19, 2005 2:44 PM
To: '[email protected]'
Subject: RE: newbie need help

 

Hi Yixing

 

You can use the XmlCursor to insert attributes. Use the cursor to navigate to the element on which you wish to add the attributes. After that do something like the following:

 

                                    QName attQN = new QName("http://www.w3.org/2001/XMLSchema-instance",

                                                            "noNamespaceSchemaLocation",

                                                            "xsi");

                                    c.insertAttributeWithValue(attQN,

                                        "C:\\Documents and Settings\\User\\Desktop\\r&r.xsd");

 

To get an XmlCursor simply call newCursor() on any XmlObject.

 

I tried this in a test program and both the attribute and namespace declaration were automatically put in as you wish.

 

Cheers,

 

Lawrence

 


From: Yixing Ma [mailto:[EMAIL PROTECTED]
Sent: Friday, August 12, 2005 10:46 AM
To: [email protected]
Subject: newbie need help

 

Hi,

 

I just switched to XMLBeans from JAXB.

 

Now I have a question about writing to a file from XMLBeans.

 

 

<?xml version="1.0" encoding="UTF-8"?>
<Example xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Documents and Settings\User\Desktop\r&r.xsd">

 

 

I want to include

 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Documents and Settings\User\Desktop\r&r.xsd"

 

information into the newly created XML file. But don't know how. Anyone can help?

 

Regards,

YODA909

 

 

 

Reply via email to