Getting "node" value?

Hi, is there anyway to get node value and not to display the tag?

If my query result reutrns:

How can I just display “ABC”?

Must I use DOM?

Hi KAren,

I’m afraid it’s me again…
It is possible to extract the result you want without using DOM (or SAX, for that matter).

You can use a combination of the string() function in the X-Query and the getQueryContentAsString() method of the TResponse class.
For example, if the query to get ABC is:
then convert it to this:

Then change your Java code to something like this:
   TConnection conn = TConnectionFactory.getInstance().newConnection(URI);
   TAccessLocation tal = TAccessLocation.newInstance(“xmldb”);
   TXMLObjectAccessor xmlAccessor = conn.newXMLObjectAccessor(tal,
   TResponse tr = xmlAccessor.query(TQuery.newInstance(“string(/Message)”));
   System.out.println(“Result: “” + tr.getQueryContentAsString() + “””);

I think that this will put you on the right track.


Hey Trevor!

I’m glad that you replied. :wink:

I’ve tried what you suggested. The outcome was:

The part where you change the query to string, I think it’s the same. Both display the same results.

I went to check the method getQueryContentAsString(), it says: If the result is a value or a set of values, the string returned is the concatenation of these values.

Anyway, the codes I’m using are:

//Instantiate an empty TXMLObject instance using the DOM object model
TXMLObject xmlObject = TXMLObject.newInstance(TDOMObjectModel.getInstance());

//Establish the Tamino connection
TConnection connection = TConnectionFactory.getInstance().newConnection(DATABASE_URI);

//Obtain a TXMLObjectAccessor with a DOM object model
TXMLObjectAccessor xmlObjectAccessor = connection.newXMLObjectAccessor(TAccessLocation.newInstance(“TCM”),TDOMObjectModel.getInstance());

//Invoke the query operation
TQuery query = TQuery.newInstance(docName + “[//RIREG~=’" + name + "’]/ID”);
TResponse response = xmlObjectAccessor.query(query);

TXMLObjectIterator myIterator = response.getXMLObjectIterator();

while (myIterator.hasNext())
TXMLObject xmlObjectReturned =;

//Print out the results and number of results are returned
System.out.println("Number: " + searchCount);

Thank you for your help,

Hey KAren,

I’m not sure where we should go from here.

The query you are using in your code is quite likely to return multiple documents - it uses the ~= and wildcards…

What would you like to have the query return - the list of ID values (not ino:id, but the ID element) without the tags?


Hi KAren,

I’m going to take a risk and say that I don’t think it is possible to do this with a single XPath expression.
(Though better heads than mine may easily prove me wrong!)

I think that there are a number of options open to you:
   * remove the tags from the result using XSL
   * expand your existing code
   * dive into W3C XQuery…

If you choose the third option, you can try using the “QuiP” tool to execute XQuery against Tamino.
(See this forum.)


Hey Trevor,

Do you think it’s possible to use DOM to extract out the values?

Just a crazy thought,

Hi KAren,

sure - you can do it easily with the DOM.

Your existing code contains this chunk:
while (myIterator.hasNext())
   TXMLObject xmlObjectReturned =;

Perhaps this is what you need:
while ( myIterator.hasNext() ) {
   TXMLObject xmlObjectReturned =;
   Element el = (Element)xmlObjectReturned.getElement();
   // The value is the first child…
   Node val = el.getFirstChild();
   System.out.println("\t" + val.getNodeValue());

(You’ll need to import Element & Node from the org.w3c.dom package.)

I hope this helps you out!

Hi Trevor!

Thanks for helping me out all the time!

I took one of your advices. I wrote a program out to remove the tag. It works…it just need a little brain exercise and that will do the trick.

Thank you once again!