简体   繁体   English

如何在字符串(不是文档)的内容上使用Linq-to-XML?

[英]How do I use Linq-to-XML on the contents of a string (not document)?

Hi and thanks for looking! 您好,感谢您的光临!

Background 背景

I am working on a developer tool for our dev team that parses content from MS Word into a Windows form with text boxes. 我正在为我们的开发团队开发一个开发人员工具,该工具将MS Word中的内容解析为带有文本框的Windows窗体。 We do some processing on the text, then submit the form to a database. 我们对文本进行一些处理,然后将表单提交到数据库。

Some of the textboxes in the form contain Word XML which we need to clean up and convert to our own XML to later use with XSLT. 表单中的某些文本框包含Word XML,我们需要清理这些Word XML并将其转换为我们自己的XML,以便以后与XSLT结合使用。

When the form populates, I would like to take the Word XML and use Linq to search for certain tags (example: <w:t>SOME TEXT</w:t> ) and convert it to our own XML ( <Text>SOME TEXT</Text> ) before it gets to the textbox. 填充表单时,我想使用Word XML并使用Linq搜索某些标签(例如: <w:t>SOME TEXT</w:t> )并将其转换为我们自己的XML( <Text>SOME TEXT</Text> ),然后再进入文本框。

Question

How do I use Linq-to-Xml on the contents retrieved from a string in the pre-processing stage? 在预处理阶段如何在从字符串检索的内容上使用Linq-to-Xml? I know how to instantiate an XDocument, but this is just a string so I am stumped. 我知道如何实例化XDocument,但这只是一个字符串,所以我很困惑。 Probably missing something simple. 可能缺少一些简单的东西。

Thanks! 谢谢!

您可以使用XDocument.Parse方法从字符串创建XDocument

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM