很遗憾这长篇留言... 但我头痛
我有一英里长的xml文件 我需要提取一个列表, 使用不同的值, 并传递到网络转换。
我用 xslt 和 键完成了任务, 但努力迫使服务器屈膝 。
Description: hundreds of products in xml, all with a number of named and Id ed cattegories, all categories with at least one subcategory with name and id.
类别与 ID 不同, 所有子类别都与该类别不同:
简化示例形成巨大的文件( 留下大量信息与任务无关) :
<?xml version="1.0" encoding="utf-8"?>
<root>
<productlist>
<product id="1">
<name>Some Product</name>
<categorylist>
<category id="1">
<name>cat1</name>
<subcategories>
<subcat id="1">
<name>subcat1</name>
</subcat>
<subcat id="2">
<name>subcat1</name>
</subcat>
</subcategories>
</category>
<category id="2">
<name>cat1</name>
<subcategories>
<subcat id="1">
<name>subcat1</name>
</subcat>
</subcategories>
</category>
<category id="3">
<name>cat1</name>
<subcategories>
<subcat id="1">
<name>subcat1</name>
</subcat>
</subcategories>
</category>
</categorylist>
</product>
<product id="2">
<name>Some Product</name>
<categorylist>
<category id="1">
<name>cat1</name>
<subcategories>
<subcat id="2">
<name>subcat2</name>
</subcat>
<subcat id="4">
<name>subcat4</name>
</subcat>
</subcategories>
</category>
<category id="2">
<name>cat2</name>
<subcategories>
<subcat id="1">
<name>subcat1</name>
</subcat>
</subcategories>
</category>
<category id="3">
<name>cat3</name>
<subcategories>
<subcat id="1">
<name>subcat1</name>
</subcat>
</subcategories>
</category>
</categorylist>
</product>
</productlist>
</root>
<强度 > 发展结果: 强 >
<?xml version="1.0" encoding="utf-8"?>
<root>
<maincat id="1">
<name>cat1</name>
<subcat id="1"><name>subcat1</name></subcat>
<subcat id="2"><name>subcat2</name></subcat>
<subcat id="3"><name>subcat3</name></subcat>
</maincat>
<maincat id="2">
<name>cat2</name>
<subcat id="1"><name>differentsubcat1</name></subcat>
<subcat id="2"><name>differentsubcat2</name></subcat>
<subcat id="3"><name>differentsubcat3</name></subcat>
</maincat>
<maincat id="2">
<name>cat2</name>
<subcat id="1"><name>differentsubcat1</name></subcat>
<subcat id="2"><name>differentsubcat2</name></subcat>
<subcat id="3"><name>differentsubcat3</name></subcat>
</maincat>
</root>
(2000年产品将产生10类产品,5至15个子类)
尝试过的事情:
- Xslt with keys - works fine, but pooooor performance
与林克玩耍:
IEnumerable<XElement> mainCats = from Category1 in doc.Descendants("product").Descendants("category") select Category1; var cDoc = new XDocument(new XDeclaration("1.0", "utf-8", null), new XElement("root")); cDoc.Root.Add(mainCats); cachedCategoryDoc = cDoc.ToString();
结果是“只有类别”(没有类别或亚类的不同值)
将同样的xLst应用到这个上面, 并取得了相当好的性能... 但仍然远远不能使用...
我可以运用某种魔法 与林格语句 获得想要的输出吗?
一卡车好货 运到那些可以指向我 向正确方向的人...
// 17个
注:
- I am not stuck on using linq/XDocument if anyone has better options
- Currently on .net 3.5, can switch to 4 if needed