Retrieving user information [message #45221] |
Fri, 21 May 2004 17:57  |
Eclipse User |
|
|
|
Ed,
I am trying to retrieve the content of <xs:documentation> nodes in my XSD
document. The logic I am trying is shown below but it does not return the
content. I am unsure if Element.getNodeValue() is really the correct method
to retrieve the content of the document node but I do not see any other
methods via the Element API. Also, examining all the Annotation contents
while running my code in debug has not given me any ideas. Do you have any
suggestions?
XSDAnnotation annotation = entity.getAnnotation();
if(annotation != null){
final Iterator userInfos =
annotation.getUserInformation().iterator();
while(userInfos.hasNext() ){
final Element userInfo = (Element)userInfos.next();
final String value = userInfo.getNodeValue();
if (value != null) {
return value;
}
}
}
Thanks in advance,
Dennis Fuglsang
|
|
|
|
Re: Retrieving user information [message #45409 is a reply to message #45319] |
Tue, 25 May 2004 10:12  |
Eclipse User |
|
|
|
Thanks Ed.
I also found some example code in the org.apache.xerces.util.DOMUtil class
that does what you are indicating.
public static String getChildText(Node node) {
// is there anything to do?
if (node == null) {
return null;
}
// concatenate children text
StringBuffer str = new StringBuffer();
Node child = node.getFirstChild();
while (child != null) {
short type = child.getNodeType();
if (type == Node.TEXT_NODE) {
str.append(child.getNodeValue());
}
else if (type == Node.CDATA_SECTION_NODE) {
str.append(getChildText(child));
}
child = child.getNextSibling();
}
// return text value
return str.toString();
} // getChildText(Node):String
"Ed Merks" <merks@ca.ibm.com> wrote in message
news:40B320A2.2C6B50B4@ca.ibm.com...
> Dennis,
>
> According to the Javadoc, Element.getNodeValue will always give you null.
I
> think you want to access the children, i.e., getFirstChild followed by
> getNextSibling, which will yield the text nodes and other child nodes.
>
>
> Dennis Fuglsang wrote:
>
> > Ed,
> >
> > I am trying to retrieve the content of <xs:documentation> nodes in my
XSD
> > document. The logic I am trying is shown below but it does not return
the
> > content. I am unsure if Element.getNodeValue() is really the correct
method
> > to retrieve the content of the document node but I do not see any other
> > methods via the Element API. Also, examining all the Annotation
contents
> > while running my code in debug has not given me any ideas. Do you have
any
> > suggestions?
> > XSDAnnotation annotation = entity.getAnnotation();
> > if(annotation != null){
> > final Iterator userInfos =
> > annotation.getUserInformation().iterator();
> > while(userInfos.hasNext() ){
> > final Element userInfo = (Element)userInfos.next();
> > final String value = userInfo.getNodeValue();
> > if (value != null) {
> > return value;
> > }
> > }
> > }
> >
> > Thanks in advance,
> > Dennis Fuglsang
>
|
|
|
Re: Retrieving user information [message #587428 is a reply to message #45221] |
Tue, 25 May 2004 06:32  |
Eclipse User |
|
|
|
Dennis,
According to the Javadoc, Element.getNodeValue will always give you null. I
think you want to access the children, i.e., getFirstChild followed by
getNextSibling, which will yield the text nodes and other child nodes.
Dennis Fuglsang wrote:
> Ed,
>
> I am trying to retrieve the content of <xs:documentation> nodes in my XSD
> document. The logic I am trying is shown below but it does not return the
> content. I am unsure if Element.getNodeValue() is really the correct method
> to retrieve the content of the document node but I do not see any other
> methods via the Element API. Also, examining all the Annotation contents
> while running my code in debug has not given me any ideas. Do you have any
> suggestions?
> XSDAnnotation annotation = entity.getAnnotation();
> if(annotation != null){
> final Iterator userInfos =
> annotation.getUserInformation().iterator();
> while(userInfos.hasNext() ){
> final Element userInfo = (Element)userInfos.next();
> final String value = userInfo.getNodeValue();
> if (value != null) {
> return value;
> }
> }
> }
>
> Thanks in advance,
> Dennis Fuglsang
|
|
|
Re: Retrieving user information [message #587478 is a reply to message #45319] |
Tue, 25 May 2004 10:12  |
Eclipse User |
|
|
|
Thanks Ed.
I also found some example code in the org.apache.xerces.util.DOMUtil class
that does what you are indicating.
public static String getChildText(Node node) {
// is there anything to do?
if (node == null) {
return null;
}
// concatenate children text
StringBuffer str = new StringBuffer();
Node child = node.getFirstChild();
while (child != null) {
short type = child.getNodeType();
if (type == Node.TEXT_NODE) {
str.append(child.getNodeValue());
}
else if (type == Node.CDATA_SECTION_NODE) {
str.append(getChildText(child));
}
child = child.getNextSibling();
}
// return text value
return str.toString();
} // getChildText(Node):String
"Ed Merks" <merks@ca.ibm.com> wrote in message
news:40B320A2.2C6B50B4@ca.ibm.com...
> Dennis,
>
> According to the Javadoc, Element.getNodeValue will always give you null.
I
> think you want to access the children, i.e., getFirstChild followed by
> getNextSibling, which will yield the text nodes and other child nodes.
>
>
> Dennis Fuglsang wrote:
>
> > Ed,
> >
> > I am trying to retrieve the content of <xs:documentation> nodes in my
XSD
> > document. The logic I am trying is shown below but it does not return
the
> > content. I am unsure if Element.getNodeValue() is really the correct
method
> > to retrieve the content of the document node but I do not see any other
> > methods via the Element API. Also, examining all the Annotation
contents
> > while running my code in debug has not given me any ideas. Do you have
any
> > suggestions?
> > XSDAnnotation annotation = entity.getAnnotation();
> > if(annotation != null){
> > final Iterator userInfos =
> > annotation.getUserInformation().iterator();
> > while(userInfos.hasNext() ){
> > final Element userInfo = (Element)userInfos.next();
> > final String value = userInfo.getNodeValue();
> > if (value != null) {
> > return value;
> > }
> > }
> > }
> >
> > Thanks in advance,
> > Dennis Fuglsang
>
|
|
|
Powered by
FUDForum. Page generated in 0.05354 seconds