首页 > 解决方案 > 从 Azure 逻辑应用中的 XML 文档解析 Word 格式的文本

问题描述

我正在尝试从 SharePoint 表单库中解析 XML 文件,其中用户已将格式化的 Word 文档文本复制/粘贴到文本字段中。结果是 XML 中的 XML。我在获取内容时遇到了麻烦,但在另一个问题的帮助下,这种语法有效xpath(xml(outputs('Get_file_content')?['body']),'//*[local-name()="myFields"]//following-sibling::*[local-name()="Request_Description"]')[0]。结果是这样的

<my:Request_Description xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2017-05-05T14:19:13">
  <xhtml:html xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <xhtml:div>
      <xhtml:font size="1" face="CIDFont+F6">
        <xhtml:font size="1" face="CIDFont+F6">
          <xhtml:p>This is where the request description goes and the result we want</xhtml:p>
</xhtml:font>
      </xhtml:font>
    </xhtml:div>
</xhtml:html>
</my:Request_Description>

如何仅提取描述文本?我想知道是否xpath需要调整我的第一个语句以免拉回整个元素。

更新 - 我没有提到上面只是用户输入该字段的一个示例,每个表单都会有所不同。例如,这里是可以在该字段中找到的另一个示例。

<my:Request_Description xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2017-05-05T14:19:13">
  <xhtml:html xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <xhtml:div>test random double quote inside title "here" test and carriage<xhtml:br />return</xhtml:div>
</xhtml:html>
</my:Request_Description>

这是由表单上的 RTF 控件引起的,用户可以在该控件中输入表单上的文本框,然后该控件将其转换为您看到的 XML。由于没有一致性,我想知道 usingxpath是否不是一个可行的选择,但我不确定还能做什么。

标签: xmlxml-parsingazure-logic-apps

解决方案


你可以使用这个表达式:

xpath(xml(outputs('Get_file_content')?['body']), 'string(/*[local-name()="Request_Description"]/*[local-name()="html"]/*[local-name()="div"]/*[local-name()="font"]/*[local-name()="font"]/*[local-name()="p"])')

可以参考这个官方文档来参考xpath.

=========================更新========================= ==

您可以使用trim,然后使用此表达式:

trim(xpath(xml(outputs('Get_file_content')?['body']), 'string(/*[local-name()="Request_Description"])'))

推荐阅读