2

I have Location category and under this category: region->countries->cities.I want to get the hierarchical category data in XML in TOM.NET by passing parent's categoryID. I just want basic info e.g. tcmId , Title

I am trying below code :

TaxonomiesOwlFilter filter = new TaxonomiesOwlFilter(Engine.GetSession());
filter.RootCategories = new Category[] { new Category(Engine.GetSession(), 
                                                      new TcmUri("tcm:xx-xxxx-xxx")) };
Repository rep = this.Publication as  Repository;

Package.AddXml("Keywordxml", rep.GetTaxonomiesOwl(filter).ToString());

But while executing the code, I am getting the below error:

"Invalid type:Category."

I really don't know how to do that, just trying solution found on sites. Please let me know.

  • Is the category you are passing a root category (that is; it does not have any parents)? – Bjørn van Dommelen Jan 19 '15 at 12:59
  • yes , I am passing root category. – Bhagat Jan 19 '15 at 14:31
2

Your code looks okay but I think you should use "OuterXml" or "InnerXml" in-place of "ToString", when adding the xml to package.

So the code will be rep.GetTaxonomiesOwl(filter).OuterXml inplace of rep.GetTaxonomiesOwl(filter).ToString().

Well, rep.GetTaxonomiesOwl(filter) return a object of type System.Xml.XmlElement. So if you use ToString() method, it will just returns a string that represents the XmlElement object.

Update:

Why are you creating a "New" category object? please get the category using engine.GetObject() and use it in filter. I am assuming, you get the right publication in Repository rep = this.Publication as Repository.

Here is the code. I did not run it but I guess it should work:

TaxonomiesOwlFilter filter = new TaxonomiesOwlFilter(engine.GetSession());
Category cat = engine.GetObject(new TcmUri("tcm:xxx-xxxxx-xxx")) as Category;
filter.RootCategories = new Category[] { cat };
Repository rep = this.Publication as Repository;
package.PushItem("Keywordxml", package.CreateXmlDocumentItem(ContentType.Xml, rep.GetTaxonomiesOwl(filter).OwnerDocument));
| improve this answer | |
  • Thanks Saurabh Outerxml is also return string but problem is I am getting error in above code. "Invalid type:Category." I think something releated to "Repository". Let me know if you have any views – Bhagat Jan 18 '15 at 8:25
  • 1
    well, both returns the string but ToString() retruns a string representing the object. But OuterXml returns the xml as string. – Saurabh Gangwar Jan 18 '15 at 12:33
  • 1
    I've run Saurabh's code (with a different TCMID of course) and it works fine except for this.Publication (which I replaced with engine.GetObject("tcm:0-1-1"); if the exact same code does not work I would try next with a new category with only a few keywords to isolate the problem – Bjørn van Dommelen Jan 21 '15 at 14:42
  • Saurabh , Code is working fine and give me hierarchical result as expected. Thanks. One more thing using this when we get the keyword detail , it contain the Metadata info but which meta schema attached to keyword is missing like schema name or href. Can we do get that info too along with the same result ? – Bhagat Jan 23 '15 at 12:33
  • Please go through the API document and post a new question if you unable to get help from the document. – Saurabh Gangwar Jan 23 '15 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.