简体   繁体   English

无法在Azure逻辑应用程序中解析具有空内容的xml

[英]Unable to parse xml with null content in azure logic apps

I am getting an XML with following structure 我正在获取具有以下结构的XML

<?xml version="1.0" encoding="UTF-8"?>
<Data>
   <datym>
     <bla bla>
   </datym>
   <datym>
     <bla bla>
   </datym>
</Data>

This i can successfully parsed to json and do all the work. 我可以成功解析为json并完成所有工作。 Sometimes i am getting an empty xml with following format. 有时我得到以下格式的空xml。

<?xml version="1.0" encoding="UTF-8"?>
<Data></data>

This however fail to parse as an xml or json using logic apps.So how do i do a validation if this is parsable XML or the empty XML? 但是,这无法使用逻辑应用程序解析为xml或json。那么,如果这是可解析的XML或空的XML,我该如何进行验证? i thought of using contains() function after initiate a string but this is huge performance hit. 我想到了在启动字符串后使用contains()函数,但这对性能造成了巨大影响。

Thanks for your ideas. 感谢您的想法。

I thought your empty xml example is till parsable. 我以为您的空xml示例可以解析。 I tried to parse a xml file to a json file. 我试图将xml文件解析为json文件。 This is my xml content. 这是我的xml内容。

<Invoices
xmlns="http://gateway.com/schemas/Invoices"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://gateway..com/schemas/Invoices Invoices.xsd">
<DocumentInfo></DocumentInfo>
<Header></Header>
<Documents></Documents>
</Invoices>

After parse, this is the json content: 解析后,这是json内容:

{
  "Invoices": {
    "@xmlns": "http://gateway.com/schemas/Invoices",
    "@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
    "@xsi:schemaLocation": 
    "http://gateway..com/schemas/InvoicesInvoices.xsd",
    "DocumentInfo": "",
    "Header": "",
    "Documents": ""
  }
}

So maybe you could refer to my Logic App flow. 因此,也许您可​​以参考我的Logic App流程。 I used a xml file as a display. 我使用xml文件作为显示。

在此处输入图片说明

Hope this could help you, if you still have other questions, please let me know. 希望这对您有帮助,如果您还有其他问题,请告诉我。

I actually find a way around this. 我实际上找到了解决此问题的方法。 So i thought i will answer my own so future others would find it useful. 所以我想我会自己回答,以便将来其他人会觉得有用。

My method is using XPATH. 我的方法是使用XPATH。

Simply check the first node. 只需检查第一个节点。 If it returns empty array then its empty otherwise go with the normal processing. 如果返回空数组,则返回空数组,否则进行常规处理。

xpath(xml(base64ToString(variables('content'))),'//datym')

or 要么

xpath(xml(base64ToString(variables('content'))),'//datym[1]')

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

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