Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » Retrieving user information
Retrieving user information [message #45221] Fri, 21 May 2004 21:57 Go to next message
Dennis Fuglsang is currently offline Dennis FuglsangFriend
Messages: 77
Registered: July 2009
Member
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 #45319 is a reply to message #45221] Tue, 25 May 2004 10:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.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 #45409 is a reply to message #45319] Tue, 25 May 2004 14:12 Go to previous message
Dennis Fuglsang is currently offline Dennis FuglsangFriend
Messages: 77
Registered: July 2009
Member
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 10:32 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33264
Registered: July 2009
Senior Member
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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Retrieving user information [message #587478 is a reply to message #45319] Tue, 25 May 2004 14:12 Go to previous message
Dennis Fuglsang is currently offline Dennis FuglsangFriend
Messages: 77
Registered: July 2009
Member
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
>
Previous Topic:How to parse a schema from an InputStream
Next Topic:NPE during schema validation
Goto Forum:
  


Current Time: Sat Dec 21 16:53:56 GMT 2024

Powered by FUDForum. Page generated in 0.03798 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top