split-apply-combine 相关问题


AnimationSet 未按预期执行顺序动画

如果我手动执行多个连续动画。它按预期工作。这是我的可行代码 扩展.xml 如果我手动执行多个连续动画。它按预期工作。这是我的可行代码 scale_up.xml <?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:fromXScale="1.0" android:fromYScale="1.0" android:toXScale="1.1" android:toYScale="1.1" android:pivotX="50%" android:pivotY="50%" android:fillAfter="true" android:interpolator="@android:anim/decelerate_interpolator" android:duration="@android:integer/config_shortAnimTime" /> scale_down.xml <?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:fromXScale="1.1" android:fromYScale="1.1" android:toXScale="1.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:fillAfter="true" android:interpolator="@android:anim/decelerate_interpolator" android:duration="@android:integer/config_shortAnimTime" /> 手动执行连续动画 public void startAnimation(Button button) { // Define the scale up animation Animation scaleUpAnimation = AnimationUtils.loadAnimation(this, R.anim.scale_up); // Define the scale down animation Animation scaleDownAnimation = AnimationUtils.loadAnimation(this, R.anim.scale_down); scaleUpAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { button.startAnimation(scaleDownAnimation); } @Override public void onAnimationRepeat(Animation animation) { } }); button.startAnimation(scaleUpAnimation); } 结果 但是,如果我尝试使用 AnimationSet 替换上述代码,动画结果就会损坏。 public void startAnimation(Button button) { // Define the scale up animation Animation scaleUpAnimation = AnimationUtils.loadAnimation(this, R.anim.scale_up); // Define the scale down animation Animation scaleDownAnimation = AnimationUtils.loadAnimation(this, R.anim.scale_down); // Create an AnimationSet to combine both animations // (It makes no difference whether I am using true or false) AnimationSet animationSet = new AnimationSet(true); animationSet.addAnimation(scaleUpAnimation); animationSet.addAnimation(scaleDownAnimation); // Apply the animation to the button button.startAnimation(animationSet); } 使用AnimationSet的结果(动画不流畅) 我可以知道为什么AnimationSet不起作用吗?谢谢。 我们需要使用setStartOffset来延迟第二个动画的执行。这是解决上述问题的完整代码片段。 public void startAnimation(Button button) { int config_shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); // Define the scale up animation ScaleAnimation scaleUpAnimation = new ScaleAnimation( 1f, 1.02f, 1f, 1.02f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f ); scaleUpAnimation.setInterpolator(new DecelerateInterpolator()); scaleUpAnimation.setDuration(config_shortAnimTime); scaleUpAnimation.setFillAfter(true); // Define the scale down animation ScaleAnimation scaleDownAnimation = new ScaleAnimation( 1.02f, 1f, 1.02f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f ); scaleDownAnimation.setInterpolator(new AccelerateInterpolator()); scaleDownAnimation.setDuration(config_shortAnimTime); scaleDownAnimation.setFillAfter(true); scaleDownAnimation.setStartOffset(scaleUpAnimation.getDuration()); // Create an AnimationSet to combine both animations AnimationSet animationSet = new AnimationSet(false); animationSet.addAnimation(scaleUpAnimation); animationSet.addAnimation(scaleDownAnimation); // Apply the animation to the button button.startAnimation(animationSet); }


在Combine Swift 中声明初始值后,Sink.receive() 不会被调用

问题: 我在代码示例中使用了 Publisher,该代码示例是我根据此处的代码示例编写的,[https://developer.apple.com/documentation/combine/observableobject][1]。我希望打印声明我...


为什么 std::apply 使用函数模板会失败,但使用具有显式模板参数列表的 lambda 表达式却不会失败? [重复]

在查看 cpprefrence 中的 std::apply 引用时,我们可以看到函数模板不能作为 std::apply 的可调用对象传递。让我们考虑以下函数模板: 模板<


在 Redis 中聚合时如何使用 APPLY format() 加载 JSON 值?

我正在尝试使用 RedisJson 在 Redis 上运行 FT.AGGREGATE 命令的 APPLY format(...) 子表达式,但尝试使用 JsonPath 作为格式参数会出现未知符号错误。 我有...



Python 代码可让我从文本文件中查找名称和 ID

员工 = {} def load_employees(): 以 open("employees.txt") 作为文件: 对于文件中的行: id_num, full_name = line.strip().split(",") 首先...


仅从文件中读取 1 个值

Python 文件: 名称=[] 以 open("names.csv") 作为文件: 对于文件中的行: 名称、颜色 = line.rstrip().split(",") print(f"{名称}, {颜色}") CSV ...


在 TCL 中检查输入是否为 lambda

我在 TCL 中遇到了争论。除了使用catch {apply $arg}之外,我如何判断它是否是一个lambda函数?谢谢


VSCode 仅从 csv 文件读取 1 个值[已关闭]

Python 文件: 名称=[] 以 open("names.csv") 作为文件: 对于文件中的行: 名称、颜色 = line.rstrip().split(",") print(f"{名称}, {颜色}") CSV ...


Python 代码仅从 csv 文件读取 1 个值 [已关闭]

Python 文件: 名称=[] 以 open("names.csv") 作为文件: 对于文件中的行: 名称、颜色 = line.rstrip().split(",") print(f"{名称}, {颜色}") CSV ...


失败后如何使用检查站点重复代理服务器

我的代码在失败后不会重复 导入请求 将 open("valid_proxies.txt", "r") 作为 f: 代理 = f.read().split(" ”) site_to_check = ["https://open.


流程图 - Python

我需要为给定的流程图编写一个程序 我的代码: x,y,d=列表(map(int,input().split())) 温度=0 而 x<=y: x=temp while temp>0: 如果温度%10==d: ...


c# 某些元素未显示在列表交集处

我正在尝试获取两个列表的共同元素。示例如下: var control = "F, H, S, W".Split(',').ToList(); var 驱动器 = 新列表 {"C", "...


我无法从 Huggingface 下载数据集

从数据集导入load_dataset 数据集 = load_dataset(path='seamew/THUCNewsTitle', split='train') 我的网络没问题,但控制台总是显示: 回溯(最近一次调用最后一次): 文件“/


对整数中的数字进行排序的最有效方法是什么?

例如,将616转为166,或将885740转为045788。我尝试过: parseInt(n.toString().split("").sort().join("")) 它确实有效,但是有没有更高效的方法?


Pandas - Lambda 内部应用以返回一行

我原本期望在 Pandas DataFrame 中的 apply 中使用 lambda 函数时获得整行,但看起来我得到了一个“单个元素”。 看那段代码: # 数据样本 评论_2 = pd。


为什么整数值越高,程序运行时间就越长?

我正在使用此存储库中的文本文件。 f = open("words_alpha.txt") 列表 =f.read() f.close() # word 是随机字母列表 列表 = 列表.split() 对于列表 [:] 中的 i: 如果 len(i) &...


Snowflake SQL 中 T-SQL CROSS APPLY 的等效项

我有一个包含 4 列的表格:状态、笔、铅笔、纸,最后 3 列显示二进制值(1 或 0)。 国家笔 铅笔 纸 纽约 1 0 1 CA 1 1 1 德克萨斯州...


如何分割多个不同的字符,同时保留该字符,但又不在空白处?

尝试/失败地分割两个不同的字符,但也不分割空间。 #!/usr/bin/env perl 使用严格; 我的 $line = "-abc=123 +def=456 -ghi 789"; 我的@arr = split(/([+-]\S+)/,$line); 为我的$


Git stash apply 已删除所有未暂存的文件

我只需使用 git stash 就可以 git stash 存储我的本地文件。我有一些暂存的(和本地提交的)文件,以及一些未暂存的更改(在相同的文件中,我按块暂存)。 然后,我...


显示输入类型日期的占位符文本

占位符不适用于直接输入类型日期和日期时间本地。 占位符不适用于直接输入类型 date 和 datetime-local。 <input type="date" placeholder="Date" /> <input type="datetime-local" placeholder="Date" /> 该字段在桌面上显示 mm/dd/yyy,而在移动设备上则不显示任何内容。 如何显示 Date 占位符文本? 使用onfocus="(this.type='date')",例如: <input required="" type="text" class="form-control" placeholder="Date" onfocus="(this.type='date')"/> 使用onfocus和onblur...这是一个例子: <input type="text" placeholder="Birth Date" onfocus="(this.type='date')" onblur="if(this.value==''){this.type='text'}"> 在这里,我尝试了 data 元素中的 input 属性。并使用 CSS 应用所需的占位符 <input type="date" name="dob" data-placeholder="Date of birth" required aria-required="true" /> input[type="date"]::before { content: attr(data-placeholder); width: 100%; } /* hide our custom/fake placeholder text when in focus to show the default * 'mm/dd/yyyy' value and when valid to show the users' date of birth value. */ input[type="date"]:focus::before, input[type="date"]:valid::before { display: none } <input type="date" name="dob" data-placeholder="Date of birth" required aria-required="true" /> 希望这有帮助 <input type="text" placeholder="*To Date" onfocus="(this.type='date')" onblur="(this.type='text')" > 这段代码对我有用。只需使用这个即可 对于 Angular 2,你可以使用这个指令 import {Directive, ElementRef, HostListener} from '@angular/core'; @Directive({ selector: '[appDateClick]' }) export class DateClickDirective { @HostListener('focus') onMouseFocus() { this.el.nativeElement.type = 'date'; setTimeout(()=>{this.el.nativeElement.click()},2); } @HostListener('blur') onMouseBlur() { if(this.el.nativeElement.value == ""){ this.el.nativeElement.type = 'text'; } } constructor(private el:ElementRef) { } } 并像下面一样使用它。 <input appDateClick name="targetDate" placeholder="buton name" type="text"> 对于 React,你可以这样做。 const onDateFocus = (e) => (e.target.type = "datetime-local"); const onDateBlur = (e) => (e.target.type = "text"); . . . <input onFocus={onDateFocus} onBlur={onDateBlur} type="text" placeholder="Event Date" /> 我是这样做的: var dateInputs = document.querySelectorAll('input[type="date"]'); dateInputs.forEach(function(input) { input.addEventListener('change', function() { input.classList.add('no-placeholder') }); }); input[type="date"] { position: relative; } input[type="date"]:not(.has-value):before { position: absolute; left: 10px; top: 30%; color: gray; background: var(--primary-light); content: attr(placeholder); } .no-placeholder:before{ content:''!important; } <input type="date" name="my-date" id="my-date" placeholder="My Date"> 现代浏览器使用 Shadow DOM 来方便输入日期和日期时间。因此,除非浏览器出于某种原因选择回退到 text 输入,否则不会显示占位符文本。您可以使用以下逻辑来适应这两种情况: ::-webkit-calendar-picker-indicator { @apply hidden; /* hide native picker icon */ } input[type^='date']:not(:placeholder-shown) { @apply before:content-[attr(placeholder)]; @apply sm:after:content-[attr(placeholder)] sm:before:hidden; } input[type^='date']::after, input[type^='date']::before { @apply text-gray-500; } 我使用了 Tailwind CSS 语法,因为它很容易理解。让我们一点一点地分解它: ::-webkit-calendar-picker-indicator { @apply hidden; /* hide native picker icon */ } 使用其 Shadow DOM 伪元素选择器隐藏本机选择器图标(通常是日历)。 input[type^='date']:not(:placeholder-shown) { @apply before:content-[attr(placeholder)]; @apply sm:after:content-[attr(placeholder)] sm:before:hidden; } 选择所有未显示占位符的 date 和 datetime-local 输入,并且: 默认使用 placeholder 伪元素显示输入 ::before 文本 在小屏幕及以上屏幕上切换为使用 ::after 伪元素 input[type^='date']::after, input[type^='date']::before { @apply text-gray-500; } 设置 ::before 和 ::after 伪元素的样式。


Angular Material 2:修复多行错误消息

我在我的角度应用程序中使用角度材料2。当我的表单输入字段错误消息超过一行时,我遇到了问题。这是照片: 这是代码: 我在我的角度应用程序中使用角度材料 2。当我的表单输入字段错误消息超过一行时,我遇到了问题。这是照片: 这是代码: <md-error *ngIf="password.touched && password.invalid"> <span *ngIf="password.errors.required"> {{'PASSWORD_RECOVERY.FIELD_REQUIRED' | translate}} </span> <span *ngIf="password.errors.minlength || password.errors.maxlength"> {{'PASSWORD_RECOVERY.PASSWORD_LENGTH' | translate}} </span> <span *ngIf="password.errors.pattern"> {{'PASSWORD_RECOVERY.FOR_A_SECURE_PASSWORD' | translate}} </span> </md-error> 我通过阅读 github 了解到,这是 Angular 2 材料中的一个错误。有人通过自定义解决方法成功解决了这个问题吗? 问题是类为 .mat-form-field-subscript-wrapper 的元素是 position: absolute,所以它不占用实际空间。 按照 xumepadismal 在 github 上关于此问题的建议,您可以添加此 scss 作为解决我的问题的解决方法: // Workaround for https://github.com/angular/material2/issues/4580. mat-form-field .mat-form-field { &-underline { position: relative; bottom: auto; } &-subscript-wrapper { position: static; } } 它会转换静态 div 中的 .mat-form-field-subscript-wrapper 节点,并将 .mat-form-field-unterline 重新定位在输入字段之后。 正如材料 15 中在 github 讨论中提到的,可以通过将 subscriptSizing="dynamic" 添加到 mat-form-field 来解决问题。 要更改默认行为,您必须使用以下选项更新 angular.module.ts 提供程序: providers: [ { provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { subscriptSizing: 'dynamic' } } ] 这也可以在材料文档中找到 使用@mattia.corci提出的解决方案会导致错误消息被推到底部太多,从而在顶部留下不必要的空白空间。 使用 Tailwind CSS,这个解决方案对我来说适用于最新的 Angular 17: .mat-mdc-form-field { @apply w-full self-start; .mat-mdc-form-field-subscript-wrapper { @apply flex; .mat-mdc-form-field-error-wrapper { @apply static; } } } mat-form-field.ng-invalid.ng-touched { animation: example; animation-duration: 0.3s; margin-bottom: 20px; } @keyframes example { from { margin-bottom: 0; } to { margin-bottom: 20px; } } 它对我有用。


如何在 JavaScript 中转义 XML 实体?

在 JavaScript(服务器端 NodeJS)中,我正在编写一个生成 XML 作为输出的程序。 我通过连接字符串来构建 XML: str += '<' + key + '>'; str += 值; str += ' 在 JavaScript(服务器端 NodeJS)中,我正在编写一个生成 XML 作为输出的程序。 我通过连接字符串来构建 XML: str += '<' + key + '>'; str += value; str += '</' + key + '>'; 问题是:如果value包含'&'、'>'或'<'等字符怎么办? 逃离这些角色的最佳方法是什么? 或者是否有任何 JavaScript 库可以转义 XML 实体? 对于相同的结果,这可能会更有效一些: function escapeXml(unsafe) { return unsafe.replace(/[<>&'"]/g, function (c) { switch (c) { case '<': return '&lt;'; case '>': return '&gt;'; case '&': return '&amp;'; case '\'': return '&apos;'; case '"': return '&quot;'; } }); } HTML 编码只是将 &、"、'、< 和 > 字符替换为其实体等效项。顺序很重要,如果您不首先替换 & 字符,您将对某些实体进行双重编码: if (!String.prototype.encodeHTML) { String.prototype.encodeHTML = function () { return this.replace(/&/g, '&amp;') .replace(/</g, '&lt;') .replace(/>/g, '&gt;') .replace(/"/g, '&quot;') .replace(/'/g, '&apos;'); }; } 如@Johan B.W. de Vries 指出,这会对标签名称产生问题,我想澄清一下,我假设这是用于 value only 相反,如果您想解码 HTML 实体1,请确保在完成其他操作之后将 &amp; 解码为 &,这样就不会双重解码任何实体: if (!String.prototype.decodeHTML) { String.prototype.decodeHTML = function () { return this.replace(/&apos;/g, "'") .replace(/&quot;/g, '"') .replace(/&gt;/g, '>') .replace(/&lt;/g, '<') .replace(/&amp;/g, '&'); }; } 1只是基础知识,不包括&copy;到©或其他类似的东西 就图书馆而言。 Underscore.js(或 Lodash,如果您愿意)提供了一个 _.escape 方法来执行此功能。 如果您有 jQuery,这里有一个简单的解决方案: String.prototype.htmlEscape = function() { return $('<div/>').text(this.toString()).html(); }; 像这样使用它: "<foo&bar>".htmlEscape(); -> "&lt;foo&amp;bar&gt" 您可以使用以下方法。我已将其添加到原型中以便于访问。 我还使用了负前瞻,因此如果您调用该方法两次或更多次,它不会弄乱事情。 用途: var original = "Hi&there"; var escaped = original.EncodeXMLEscapeChars(); //Hi&amp;there 解码由 XML 解析器自动处理。 方法: //String Extenstion to format string for xml content. //Replces xml escape chracters to their equivalent html notation. String.prototype.EncodeXMLEscapeChars = function () { var OutPut = this; if ($.trim(OutPut) != "") { OutPut = OutPut.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"); OutPut = OutPut.replace(/&(?!(amp;)|(lt;)|(gt;)|(quot;)|(#39;)|(apos;))/g, "&amp;"); OutPut = OutPut.replace(/([^\\])((\\\\)*)\\(?![\\/{])/g, "$1\\\\$2"); //replaces odd backslash(\\) with even. } else { OutPut = ""; } return OutPut; }; 注意,如果 XML 中有 XML,那么所有的正则表达式都不好。 相反,循环字符串一次,并替换所有转义字符。 这样,您就不能两次碰到同一个角色。 function _xmlAttributeEscape(inputString) { var output = []; for (var i = 0; i < inputString.length; ++i) { switch (inputString[i]) { case '&': output.push("&amp;"); break; case '"': output.push("&quot;"); break; case "<": output.push("&lt;"); break; case ">": output.push("&gt;"); break; default: output.push(inputString[i]); } } return output.join(""); } 我最初在生产代码中使用了已接受的答案,发现大量使用时它实际上非常慢。这是一个更快的解决方案(以两倍以上的速度运行): var escapeXml = (function() { var doc = document.implementation.createDocument("", "", null) var el = doc.createElement("temp"); el.textContent = "temp"; el = el.firstChild; var ser = new XMLSerializer(); return function(text) { el.nodeValue = text; return ser.serializeToString(el); }; })(); console.log(escapeXml("<>&")); //&lt;&gt;&amp; 也许你可以试试这个, function encodeXML(s) { const dom = document.createElement('div') dom.textContent = s return dom.innerHTML } 参考 添加 ZZZZBov 的答案,我发现这更干净,更容易阅读: const encodeXML = (str) => str .replace(/&/g, '&amp;') .replace(/</g, '&lt;') .replace(/>/g, '&gt;') .replace(/"/g, '&quot;') .replace(/'/g, '&apos;'); 此外,所有五个字符都可以在这里找到,例如:https://www.sitemaps.org/protocol.html 请注意,这仅对值进行编码(如其他人所述)。 现在我们有了字符串插值和其他一些现代化改进,现在是时候进行更新了。并使用对象查找,因为它确实应该这样做。 const escapeXml = (unsafe) => unsafe.replace(/[<>&'"]/g, (c) => `&${({ '<': 'lt', '>': 'gt', '&': 'amp', '\'': 'apos', '"': 'quot' })[c]};`); 从技术上讲,&、 不是有效的 XML 实体名称字符。如果您不能信任关键变量,则应该将其过滤掉。 < and >如果您希望它们作为 HTML 实体转义,您可以使用类似 http://www.strictly-software.com/htmlencode . 如果之前有东西被逃脱,你可以尝试这个,因为这不会像许多其他人那样双重逃脱 function escape(text) { return String(text).replace(/(['"<>&'])(\w+;)?/g, (match, char, escaped) => { if(escaped) { return match; } switch(char) { case '\'': return '&apos;'; case '"': return '&quot;'; case '<': return '&lt;'; case '>': return '&gt;'; case '&': return '&amp;'; } }); } 这很简单: sText = ("" + sText).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;");


活动深层链接 - IllegalArgumentException:缺少必需的参数并且没有 android:defaultValue

在我的应用程序中,我有以下结构: 在我的应用程序中,我具有以下结构: <!-- AndroidManifest.xml --> <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application> <activity android:name=".DeepLinkActivity" android:exported="true" android:launchMode="singleInstancePerTask"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="myhost" android:path="/mypath" android:scheme="myscheme" /> </intent-filter> </activity> </application> </manifest> <!-- activity_deep_link.xml --> <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.fragment.app.FragmentContainerView android:id="@+id/navHostFragment" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" app:defaultNavHost="true" tools:navGraph="@navigation/my_nav_graph" /> </FrameLayout> // DeepLinkActivity.kt class DeepLinkActivity : AppCompatActivity() { private lateinit var binding: ActivityDeepLinkBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityDeepLinkBinding.inflate(layoutInflater) setContentView(binding.root) setUpNavigationGraph() } private fun setUpNavigationGraph() { val navHostFragment = supportFragmentManager .findFragmentById(binding.navHostFragment.id) as NavHostFragment val navController = navHostFragment.navController val navGraph = navController.navInflater .inflate(R.navigation.my_nav_graph) .apply { this.setStartDestination(R.id.notTheStartDestinationFragment) } val startDestinationArgs = bundleOf( "someRequiredArgumentHere" to false ) navController.setGraph(navGraph, startDestinationArgs) } } 当我通过 ADB (adb shell am start -d myscheme://myhost/mypath) 通过深度链接打开该活动时,该活动正常启动。 但是当我通过 Chrome 应用程序启动它时,应用程序崩溃了: 原因:java.lang.IllegalArgumentException:缺少必需参数“someRequiredArgumentHere”并且没有 android:defaultValue 观察:我正在使用 Safe Args 插件。 我做错了什么以及为什么行为不同? 我刚刚发现为什么在通过浏览器导航时会忽略 startDestinationArgs。 如果我们检查NavController#setGraph(NavGraph, Bundle?)的内部代码,如果没有发生深层链接,NavController#onGraphCreated(Bundle?)只会使用startDestinationArgs。 作为一种解决方法,在设置导航图之前,我只需清除活动的意图(但这可能不是解决该问题的最佳方法)


如何使用 XML 查询功能从 XML 节点查询值

我有以下 XML 数据: 声明@x XML 设置@x=' 订购 我有以下 XML 数据: DECLARE @x XML SET @x='<Orders> <HeadingSection> <DocumentNameCode>Order</DocumentNameCode> <DetailSection> <LineItem LineItemNumber="10"> <ItemId>123456789</ItemId> <ItemTypeId>EN</ItemTypeId> <AdditionalProductId Qualifier="ProductId"> <Item> <ItemId>ABC</ItemId> <TypeId>SA</TypeId> </Item> </AdditionalProductId> <AdditionalProductId Qualifier="ProductId"> <Item> <ItemId>XYZ</ItemId> <TypeId>IN</TypeId> </Item> </AdditionalProductId> </LineItem> </DetailSection> <SummarySection/> </HeadingSection> </Orders>' 我已经使用了以下T-Sql脚本(必须有光标) DECLARE @xmlQuittungPOS XML DECLARE quittungCurPOS CURSOR FOR SELECT QuittungXMLPOS = T.X.query('.') FROM @x.nodes('/Orders/HeadingSection/DetailSection/LineItem') AS T(X) OPEN quittungCurPOS FETCH NEXT FROM quittungCurPOS INTO @xmlQuittungPOS WHILE @@FETCH_STATUS = 0 BEGIN INSERT INTO dbo.tempPOS ( GTIN ,edi_PIA_SA ,edi_PIA_IN ) SELECT GTIN = T.X.query('/LineItem[ItemTypeId = "BP"]').value('(/LineItem/ItemId)[1]','VARCHAR(100)') -- funktioniert / works ,edi_PIA_SA = T.X.query('/LineItem/AdditionalProductId/Item[TypeId = "SA"]').value('(/LineItem/AdditionalProductId/Item/ItemId)[1]','VARCHAR(255)') -- funktioniert nicht / doesn't work ,edi_PIA_IN = T.X.query('/LineItem/AdditionalProductId/Item[TypeId = "IN"]').value('(/LineItem/AdditionalProductId/Item/ItemId)[1]','VARCHAR(255)') -- funktioniert nicht / doesn't work FROM @xmlQuittungPOS.nodes('/LineItem') AS T(X) FETCH NEXT FROM quittungCurPOS INTO @xmlQuittungPOS END CLOSE quittungCurPOS DEALLOCATE quittungCurPOS 1.) GTIN -> 查询有效 2.) PIA_SA 和 PIA_IN -> 查询不起作用 问题: 我认为这是因为 '/LineItem/AdditionalProductId/Item[TypeId = "SA"]' 位于附加节点中。 问题: 如何获取中TypeId“SA”和“IN”的值 <AdditionalProductId Qualifier="ProductId"> <Item> <ItemId>**ABC**</ItemId> <TypeId>SA</TypeId> </Item> </AdditionalProductId> <AdditionalProductId Qualifier="ProductId"> <Item> <ItemId>**XYZ**</ItemId> <TypeId>IN</TypeId> </Item> </AdditionalProductId> with .value('(/LineItem/AdditionalProductId/Item/ItemId)[1]','VARCHAR(255)') !处于 1 级! -- 我知道。 级别 1 上的 SA -> .value('(/LineItem/AdditionalProductId/Item/ItemId)[1]','VARCHAR(255)') 级别 2 上的 SA -> .value('(/LineItem/AdditionalProductId/Item/ItemId)[2]','VARCHAR(255)') 但我现在需要查询类型 谢谢 不清楚你在这里追求什么,所以我回答两者。如果您想要每个 Item 节点 1 行,那么您只需对 nodes 节点使用 Item 并获取 value 文本的 ItemId: DECLARE @xml xml = '<AdditionalProductId Qualifier="ProductId"> <Item> <ItemId>**ABC**</ItemId> <TypeId>SA</TypeId> </Item> </AdditionalProductId> <AdditionalProductId Qualifier="ProductId"> <Item> <ItemId>**XYZ**</ItemId> <TypeId>IN</TypeId> </Item> </AdditionalProductId> '; SELECT AP.I.value('(ItemId/text())[1]','varchar(15)') AS ItemId, AP.I.value('(TypeId/text())[1]','varchar(15)') AS TypeId FROM (VALUES(@XML))V(X) --To give impression it's against a table CROSS APPLY V.X.nodes ('AdditionalProductId/Item')AP(I); 但是,如果您希望每个不同的 TypeID 值各有 1 列,您可以在 XML 中进行过滤: SELECT X.AP.value('(AdditionalProductId/Item[TypeId[(text()[1])="SA"]]/ItemId/text())[1]','varchar(15)') AS ItemSA, X.AP.value('(AdditionalProductId/Item[TypeId[(text()[1])="IN"]]/ItemId/text())[1]','varchar(15)') AS ItemIN FROM @xml.nodes ('/')X(AP); --To give impression it's against a table 或者使用之前的查询并使用条件聚合: WITH Items AS( SELECT AP.I.value('(ItemId/text())[1]','varchar(15)') AS ItemId, AP.I.value('(TypeId/text())[1]','varchar(15)') AS TypeId FROM @xml.nodes ('AdditionalProductId/Item')AP(I)) SELECT MAX(CASE TypeID WHEN 'SA' THEN ItemId END) AS ItemSA, MAX(CASE TypeID WHEN 'IN' THEN ItemId END) AS ItemIN FROM Items;


© www.soinside.com 2019 - 2024. All rights reserved.