This post is more than 5 years old
45 Posts
0
6396
January 8th, 2009 10:00
traversing the tags of a clip
Hi guys, I am writing a method that traverses a clip and dumps its content as XML.
I am using
tag = clip.getTopTag()
and then
method query(tag) {
if (tag == null)
return
child = tag.getFirstChild()
if (child != null) {
// process recursively
query(tag)
} else
return;
while ((sibling = child.getSibling()) != null) {
// process recursively
query(tag)
}
}
The problem now is that in the while loop there is always a sibling passed back that is != null (I expected a null when there is no more
sibling?). When I compare the attributes of the last sibling with the one passed back newly by getSibling() I can see that at the end of the list
the attributes are equal; my code section here is like
FPTag sibling = null;
while ((sibling = child.getSibling()) != null) {
String _signature = java.util.Arrays.toString(sibling.getAttributes());
if (signature.equals(_signature))
break;
this.query(sibling, childrenElement, visited);
signature = _signature;
}
Chris
gstuartemc
2 Intern
•
417 Posts
0
January 9th, 2009 07:00
Just did that without any problem. I closed the Tags as I proceeded but removing those calls did not have any effect (other than causing an error on Clip close because Tags were still open, obviously). The clip was created on the US2 cluster using the "armTest1" profile if you want to test it.
FPClip theClip = new FPClip(thePool,
"818SS9SRTNUUUeDSRDQD52SBC3OG413QTT0EVK0ECTGQ31KOO0L9A",
FPLibraryConstants.FP_OPEN_ASTREE);
FPTag topTag = theClip.getTopTag();
FPTag parent = topTag.getFirstChild();
topTag.Close();
FPTag child = parent.getFirstChild();
parent.Close();
FPTag sibling;
while (child != null)
{
System.out.println("Child name " + child.getTagName());
sibling = child.getSibling();
child.Close();
child = sibling;
}
gstuartemc
2 Intern
•
417 Posts
0
January 9th, 2009 03:00
Hi Chris - have you looked at the RawRead method of the FPClip object? This inbuilt method dumps the CDF in XML format for you and may fit your needs perfectly!
The BackupContent sample code demonstrates its use.
christoph_retti
45 Posts
0
January 9th, 2009 05:00
Hi, dumping in xml is just one of the cases where I want to traverse the tag hierarchy. I would need some example that uses the
tag.getFirstChild(), tag.getSibling()
approach but did not find anything in the samples. Could you provide me with one?
gstuartemc
2 Intern
•
417 Posts
0
January 9th, 2009 05:00
I would have expected GetSibling to return null if there were no more siblings, so this may be a bug. I will look into this for you.
However, based on your comments in other discussions it looks like you will now be investigating the use of the XAM SDK? XSets are flat structures and do not have the concept of sibling relationships, but this can be easily modelled using a "reverse DNS" style naming scheme to indicate a hierarchy.
christoph_retti
45 Posts
0
January 9th, 2009 06:00
Hi, for the future I will have a look at the XAM SDK but the current code uses Centera SDK and I would like to
implement the functionality I need here before. Afterwards - when this works - I will migrate everything in one
step to XAM SDK.
So I would really appreciate this to be fixed (if this is really a bug).
Many thanks in the meantime,
Chris
gstuartemc
2 Intern
•
417 Posts
0
January 9th, 2009 06:00
Chris - I just tested this using the code below (and SDK 3.2.661) and it worked just fine for me i.e. getSibling returned null for the "youngest" child.
FPTag topTag = clip.getTopTag();
FPTag parent = new FPTag(topTag, "parent");
topTag.Close();
FPTag child = new FPTag(parent, "eldest");
child.Close();
child = new FPTag(parent, "middle");
child.Close();
child = new FPTag(parent, "youngest");
child.Close();
child = parent.getFirstChild();
parent.Close();
while (child != null)
{
System.out.println("Child name " + child.getTagName());
sibling = child.getSibling();
child.Close();
child = sibling;
}
christoph_retti
45 Posts
0
January 9th, 2009 06:00
Hi, the difference between your code and mine is that I have used an existing clip for the search and that I
keep all the tags open until I have traversed its children.
Could you do me a favor and try it with an existing clip?
christoph_retti
45 Posts
0
January 12th, 2009 05:00
Hi, you were right, it was a bug in my code. Thank you very much for your help!