Home » Language IDEs » ServerTools (WTP) » Create a WTP XML Node from an XML string
Create a WTP XML Node from an XML string [message #228524] |
Mon, 02 March 2009 09:49  |
Eclipse User |
|
|
|
Hello,
I'm working on an XML editor based on WTP XML Editor, so I have to work with
a WTP DOM.
The problem:
I have to create a Node from an XML String and insert the node to the WTP
DOM.
I can create document from a String but it won't be a WTP Document, so when
I try to insert the first child of the newly created DOM to the WTP DOM I
got the following exception:
java.lang.ClassCastException: org.apache.xerces.dom.DeferredElementImpl
cannot be cast to org.eclipse.wst.xml.core.internal.document.NodeImpl
at
org.eclipse.wst.xml.core.internal.document.NodeContainer.ins ertBefore(NodeContainer.java:269)
at
org.eclipse.wst.xml.core.internal.document.ElementImpl.inser tBefore(ElementImpl.java:693)
at
org.eclipse.wst.xml.core.internal.document.NodeContainer.app endChild(NodeContainer.java:129)
Code I use to create the DOM:
public static Document stringToDom(String xmlSource) throws SAXException,
ParserConfigurationException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(new InputSource(new StringReader(xmlSource)));
}
I browsed the wst.core code but can't find any solution.
Can anybody help me?
Thanks,
Istvan
|
|
|
Re: Create a WTP XML Node from an XML string [message #228540 is a reply to message #228524] |
Mon, 02 March 2009 10:58   |
Eclipse User |
|
|
|
Originally posted by: dcarver.starstandard.org
Have you tried the cloneNode() method?
I think the problem you are going to run into though is that you are
going from two different DOM implementations. So what you might have to
do is create a custom Clone Node method that takes the input of the
Xerces DOM node, and recreates a WTP DOM node, and returns the WTP DOM
node as it's result.
Unfortunately, WTP DOM is known not to be a 100% complete implementation
of DOM, so there are edge cases where it has problems. This appears to
be one.
Dave
Istvan wrote:
> Hello,
>
> I'm working on an XML editor based on WTP XML Editor, so I have to work
> with a WTP DOM.
>
> The problem:
> I have to create a Node from an XML String and insert the node to the
> WTP DOM.
> I can create document from a String but it won't be a WTP Document, so
> when I try to insert the first child of the newly created DOM to the WTP
> DOM I
> got the following exception:
>
> java.lang.ClassCastException: org.apache.xerces.dom.DeferredElementImpl
> cannot be cast to org.eclipse.wst.xml.core.internal.document.NodeImpl
> at
> org.eclipse.wst.xml.core.internal.document.NodeContainer.ins ertBefore(NodeContainer.java:269)
>
> at
> org.eclipse.wst.xml.core.internal.document.ElementImpl.inser tBefore(ElementImpl.java:693)
>
> at
> org.eclipse.wst.xml.core.internal.document.NodeContainer.app endChild(NodeContainer.java:129)
>
>
> Code I use to create the DOM:
> public static Document stringToDom(String xmlSource) throws
> SAXException, ParserConfigurationException, IOException {
> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
> DocumentBuilder builder = factory.newDocumentBuilder();
> return builder.parse(new InputSource(new StringReader(xmlSource)));
> }
>
> I browsed the wst.core code but can't find any solution.
>
> Can anybody help me?
>
> Thanks,
> Istvan
|
|
|
Re: Create a WTP XML Node from an XML string [message #228548 is a reply to message #228540] |
Mon, 02 March 2009 11:08   |
Eclipse User |
|
|
|
David,
I suppose one could create a WTP DOM Document and use importNode on the
root element to clone, or would that result in cast exceptions as well?
David Carver wrote:
> Have you tried the cloneNode() method?
>
> I think the problem you are going to run into though is that you are
> going from two different DOM implementations. So what you might have
> to do is create a custom Clone Node method that takes the input of the
> Xerces DOM node, and recreates a WTP DOM node, and returns the WTP DOM
> node as it's result.
>
> Unfortunately, WTP DOM is known not to be a 100% complete
> implementation of DOM, so there are edge cases where it has problems.
> This appears to be one.
>
> Dave
>
> Istvan wrote:
>> Hello,
>>
>> I'm working on an XML editor based on WTP XML Editor, so I have to
>> work with a WTP DOM.
>>
>> The problem:
>> I have to create a Node from an XML String and insert the node to the
>> WTP DOM.
>> I can create document from a String but it won't be a WTP Document,
>> so when I try to insert the first child of the newly created DOM to
>> the WTP DOM I
>> got the following exception:
>>
>> java.lang.ClassCastException:
>> org.apache.xerces.dom.DeferredElementImpl cannot be cast to
>> org.eclipse.wst.xml.core.internal.document.NodeImpl
>> at
>> org.eclipse.wst.xml.core.internal.document.NodeContainer.ins ertBefore(NodeContainer.java:269)
>>
>> at
>> org.eclipse.wst.xml.core.internal.document.ElementImpl.inser tBefore(ElementImpl.java:693)
>>
>> at
>> org.eclipse.wst.xml.core.internal.document.NodeContainer.app endChild(NodeContainer.java:129)
>>
>>
>> Code I use to create the DOM:
>> public static Document stringToDom(String xmlSource) throws
>> SAXException, ParserConfigurationException, IOException {
>> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>> DocumentBuilder builder = factory.newDocumentBuilder();
>> return builder.parse(new InputSource(new StringReader(xmlSource)));
>> }
>>
>> I browsed the wst.core code but can't find any solution.
>>
>> Can anybody help me?
>>
>> Thanks,
>> Istvan
|
|
|
Re: Create a WTP XML Node from an XML string [message #228556 is a reply to message #228548] |
Mon, 02 March 2009 11:43   |
Eclipse User |
|
|
|
Thanks for quick replies.
I checked this just now, normal cloneNode does not work, it produces the
same Exception than without using cloneNode.
Custom cloning: I thought there is a "more standard" way than doing this but
I think I will choose it, it is sure it will work.
Although, I would give a chance to the other solution.
Ed, how can I create a WTP DOM?
Can I force the stringToDom method below to create a WTP DOM?
Istvan
"Ed Merks" <Ed.Merks@gmail.com> wrote in message
news:goh09i$4bl$1@build.eclipse.org...
> David,
>
> I suppose one could create a WTP DOM Document and use importNode on the
> root element to clone, or would that result in cast exceptions as well?
>
>
> David Carver wrote:
>> Have you tried the cloneNode() method?
>>
>> I think the problem you are going to run into though is that you are
>> going from two different DOM implementations. So what you might have to
>> do is create a custom Clone Node method that takes the input of the
>> Xerces DOM node, and recreates a WTP DOM node, and returns the WTP DOM
>> node as it's result.
>>
>> Unfortunately, WTP DOM is known not to be a 100% complete implementation
>> of DOM, so there are edge cases where it has problems. This appears to
>> be one.
>>
>> Dave
>>
>> Istvan wrote:
>>> Hello,
>>>
>>> I'm working on an XML editor based on WTP XML Editor, so I have to work
>>> with a WTP DOM.
>>>
>>> The problem:
>>> I have to create a Node from an XML String and insert the node to the
>>> WTP DOM.
>>> I can create document from a String but it won't be a WTP Document, so
>>> when I try to insert the first child of the newly created DOM to the WTP
>>> DOM I
>>> got the following exception:
>>>
>>> java.lang.ClassCastException: org.apache.xerces.dom.DeferredElementImpl
>>> cannot be cast to org.eclipse.wst.xml.core.internal.document.NodeImpl
>>> at
>>> org.eclipse.wst.xml.core.internal.document.NodeContainer.ins ertBefore(NodeContainer.java:269)
>>> at
>>> org.eclipse.wst.xml.core.internal.document.ElementImpl.inser tBefore(ElementImpl.java:693)
>>> at
>>> org.eclipse.wst.xml.core.internal.document.NodeContainer.app endChild(NodeContainer.java:129)
>>>
>>> Code I use to create the DOM:
>>> public static Document stringToDom(String xmlSource) throws
>>> SAXException, ParserConfigurationException, IOException {
>>> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>>> DocumentBuilder builder = factory.newDocumentBuilder();
>>> return builder.parse(new InputSource(new StringReader(xmlSource)));
>>> }
>>>
>>> I browsed the wst.core code but can't find any solution.
>>>
>>> Can anybody help me?
>>>
>>> Thanks,
>>> Istvan
|
|
|
Re: Create a WTP XML Node from an XML string [message #228565 is a reply to message #228556] |
Mon, 02 March 2009 12:22   |
Eclipse User |
|
|
|
Istvan,
I assume there's a factory somewhere to create a Document. But then,
I'd have assumed there'd be something to create a instance from a Reader
or an InputStream...
Istvan wrote:
> Thanks for quick replies.
>
> I checked this just now, normal cloneNode does not work, it produces
> the same Exception than without using cloneNode.
> Custom cloning: I thought there is a "more standard" way than doing
> this but I think I will choose it, it is sure it will work.
>
> Although, I would give a chance to the other solution.
>
> Ed, how can I create a WTP DOM?
> Can I force the stringToDom method below to create a WTP DOM?
>
> Istvan
>
> "Ed Merks" <Ed.Merks@gmail.com> wrote in message
> news:goh09i$4bl$1@build.eclipse.org...
>> David,
>>
>> I suppose one could create a WTP DOM Document and use importNode on
>> the root element to clone, or would that result in cast exceptions as
>> well?
>>
>>
>> David Carver wrote:
>>> Have you tried the cloneNode() method?
>>>
>>> I think the problem you are going to run into though is that you are
>>> going from two different DOM implementations. So what you might
>>> have to do is create a custom Clone Node method that takes the input
>>> of the Xerces DOM node, and recreates a WTP DOM node, and returns
>>> the WTP DOM node as it's result.
>>>
>>> Unfortunately, WTP DOM is known not to be a 100% complete
>>> implementation of DOM, so there are edge cases where it has
>>> problems. This appears to be one.
>>>
>>> Dave
>>>
>>> Istvan wrote:
>>>> Hello,
>>>>
>>>> I'm working on an XML editor based on WTP XML Editor, so I have to
>>>> work with a WTP DOM.
>>>>
>>>> The problem:
>>>> I have to create a Node from an XML String and insert the node to
>>>> the WTP DOM.
>>>> I can create document from a String but it won't be a WTP Document,
>>>> so when I try to insert the first child of the newly created DOM to
>>>> the WTP DOM I
>>>> got the following exception:
>>>>
>>>> java.lang.ClassCastException:
>>>> org.apache.xerces.dom.DeferredElementImpl cannot be cast to
>>>> org.eclipse.wst.xml.core.internal.document.NodeImpl
>>>> at
>>>> org.eclipse.wst.xml.core.internal.document.NodeContainer.ins ertBefore(NodeContainer.java:269)
>>>>
>>>> at
>>>> org.eclipse.wst.xml.core.internal.document.ElementImpl.inser tBefore(ElementImpl.java:693)
>>>>
>>>> at
>>>> org.eclipse.wst.xml.core.internal.document.NodeContainer.app endChild(NodeContainer.java:129)
>>>>
>>>>
>>>> Code I use to create the DOM:
>>>> public static Document stringToDom(String xmlSource) throws
>>>> SAXException, ParserConfigurationException, IOException {
>>>> DocumentBuilderFactory factory =
>>>> DocumentBuilderFactory.newInstance();
>>>> DocumentBuilder builder = factory.newDocumentBuilder();
>>>> return builder.parse(new InputSource(new StringReader(xmlSource)));
>>>> }
>>>>
>>>> I browsed the wst.core code but can't find any solution.
>>>>
>>>> Can anybody help me?
>>>>
>>>> Thanks,
>>>> Istvan
>
|
|
| | | | |
Goto Forum:
Current Time: Wed Jul 23 13:49:51 EDT 2025
Powered by FUDForum. Page generated in 0.03956 seconds
|