- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如何使用来自一个或多个 xml 文件的两条信息填充 case
对象列表?
我尝试过的每一种方法都产生了零结果,并且检查变量给出了“枚举没有结果”。在我下面的代码示例中,我包含(注释掉)了我尝试用来实现此结果的各种方法。
如果已经有答案,请指出那个方向。我也将不胜感激任何随附的解释。
以下是代码片段:
private void gatherInfo(ref List<Case> Cases)
{
List<string> XMLFileNames = new List<string>();
foreach (string caseID in txtbxCases.Lines)
{
Cases.Add(new Case(caseID));
}
XMLFileNames.AddRange(Directory.EnumerateFiles(txtbxXMLDirectory.Text, "*", SearchOption.AllDirectories).Select(Path.GetFileName));
string currentFileName = "";
for (int i = XMLFileNames.Count - 1; i >= 0; i--)
{
currentFileName = XMLFileNames[i];
if (currentFileName.Substring(currentFileName.Length - 4, 4) != ".xml")
{
XMLFileNames.RemoveAt(i);
}
}
// Start of Area that doesn't work correctly
for (int i = XMLFileNames.Count - 1; i>=0; i--)
{
currentFileName = XMLFileNames[i];
//XElement currentDoc = XElement.Load(txtbxXMLDirectory.Text + "\\" + currentFileName);
XDocument currentDoc = XDocument.Load(txtbxXMLDirectory.Text + "\\" + currentFileName);
XElement currentDocElements = XElement.Parse(currentDoc.ToString());
for (int i2 = Cases.Count - 1; i2>=0; i2--)
{
string currentCaseID = Cases[i].GetCaseID();
IEnumerable<XElement> currentCase =
from el in currentDocElements.Descendants("Document");
where (string)el.Element("CaseNumber") == currentCaseID
select el;
///////////////////////////////////////////////////////////
//var currentCase =
// from el in currentDocElements.Descendants("IndexFields")
// where (string)el.Element("CaseNumber") == currentCaseID
// select el;
///////////////////////////////////////////////////////////
//var currentCase = currentDocElements.Descendants("IndexFields")
// .where(x => x.Element("IndexField").Value == currentCaseID);
///////////////////////////////////////////////////////////
foreach (XElement el in currentCase)
{
Cases[i].AddFile(el.Element("SRCFilename").Value, el.Element("XMLFilename").Value);
}
}
}
//foreach (string filename in XMLFileNames)
//{
// XElement currentDoc = XElement.Load(txtbxXMLDirectory.Text + "\\" + filename);
//
// foreach (var caseID in Cases)
// {
// IEnumerable<XElement> currentCase =
// from el in currentDoc.ElementsAfterSelf("IndexFields")//.Elements("IndexFields")
// //where (string)el.Element("CaseNumber") == caseID.GetCaseID()
// select el;
//
// foreach (XElement el in currentCase)
// {
// caseID.AddFile(el.Element("SRCFilename").Value, el.Element("XMLFilename").Value);
// }
// }
//}
}
下面是一个 XML 文件示例,其中包含生产 XML 文件所具有的所有嵌套。
<ImportSession>
<Batches>
<Batch BatchClassName="CaseFolder_XML">
<Documents>
<Document FormTypeName="Doc XML Form Type">
<IndexFields>
<IndexField Name="CaseNumber" Value="1"/>
<IndexField Name="XMLFilename" Value="aaa.xml"/>
<IndexField Name="SRCFilename" Value="aaa.pdf"/>
</IndexFields>
<Pages>
<Page ImportFileName="c:\aaa.pdf"/>
</Pages>
</Document>
<Document FormTypeName="Doc XML Form Type">
<IndexFields>
<IndexField Name="CaseNumber" Value="2"/>
<IndexField Name="XMLFilename" Value="aaa.xml"/>
<IndexField Name="SRCFilename" Value="aab.pdf"/>
</IndexFields>
<Pages>
<Page ImportFileName="c:\aab.pdf"/>
</Pages>
</Document>
<Document FormTypeName="Doc XML Form Type">
<IndexFields>
<IndexField Name="CaseNumber" Value="3"/>
<IndexField Name="XMLFilename" Value="aaa.xml"/>
<IndexField Name="SRCFilename" Value="aac.pdf"/>
</IndexFields>
<Pages>
<Page ImportFileName="c:\aac.pdf"/>
</Pages>
</Document>
<Document FormTypeName="Doc XML Form Type">
<IndexFields>
<IndexField Name="CaseNumber" Value="4"/>
<IndexField Name="XMLFilename" Value="aaa.xml"/>
<IndexField Name="SRCFilename" Value="aad.pdf"/>
</IndexFields>
<Pages>
<Page ImportFileName="c:\aad.pdf"/>
</Pages>
</Document>
<Document FormTypeName="Doc XML Form Type">
<IndexFields>
<IndexField Name="CaseNumber" Value="1"/>
<IndexField Name="XMLFilename" Value="aaa.xml"/>
<IndexField Name="SRCFilename" Value="aae.pdf"/>
</IndexFields>
<Pages>
<Page ImportFileName="c:\aae.pdf"/>
</Pages>
</Document>
<Document FormTypeName="Doc XML Form Type">
<IndexFields>
<IndexField Name="CaseNumber" Value="1"/>
<IndexField Name="XMLFilename" Value="aaf.xml"/>
<IndexField Name="SRCFilename" Value="aab.pdf"/>
</IndexFields>
<Pages>
<Page ImportFileName="c:\aaf.pdf"/>
</Pages>
</Document>
</Documents>
</Batch>
</Batches>
</ImportSession>
以下在生产中是正确的:
最佳答案
也许您应该阅读 Cases[i2]
而不是 Cases[i]
?
for (int i2 = Cases.Count - 1; i2>=0; i2--)
{ // ^ counter for iterating over "Cases"
string currentCaseID = Cases[i2].GetCaseID();
// ^ use correct counter here
IEnumerable<XElement> currentCase =
from el in currentDocElements.Descendants("Document");
where (string)el.Element("CaseNumber") == currentCaseID
select el;
foreach (XElement el in currentCase)
{
Cases[i2].AddFile(el.Element("SRCFilename").Value, el.Element("XMLFilename").Value);
// ^ and here
}
关于c# - 查询从不返回结果 - "Enumeration yielded no results",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13649307/
function* generatorFunction() { yield (yield 1)(yield 2)(yield 3)(); } var iterator = generatorFun
ECMAScript 6 应该带来生成器函数和迭代器。生成器函数(具有 function* 语法)返回一个迭代器。迭代器有一个 next 方法,当重复调用时,该方法会执行生成器函数的主体,并在每个 y
ECMAScript 6 应该引入生成器函数和迭代器。生成器函数(具有 function* 语法)返回迭代器。迭代器有一个 next 方法,当重复调用时,它会执行生成器函数的主体,在每个 yield
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 2 年前。 Improve t
自 python 2.5 以来,可以将 send()、throw()、close() 放入生成器中。在定义的生成器中,可以通过执行以下操作来“捕获”发送的数据: def gen(): whil
return的区别和 yield似乎很清楚,直到我发现还有 yield from以及将两者结合起来的可能性 return和 yield在完全相同的功能! 我对return的理解之后的一切都是 不是 执
假设我有这个部分,我正在尝试渲染 #layouts/_subheader.html.erb 当我在这样的 View 中使用这个部分时 Content For Yield
yield操作符是由编译器在底层实现的,该编译器生成一个实现符合 IEnumerable 的状态机的类。和 IEnumerator . 给定一个罗斯林 MethodDeclarationSyntax
$item) echo "$index $item" . PHP_EOL; } resolve(generator1()); echo PHP_EOL; resolve(gener
这个问题在这里已经有了答案: Why converting list to set is faster than converting generator to set? (1 个回答) List c
是否有一个单行代码来获取生成器并生成该生成器中的所有元素?例如: def Yearly(year): yield YEARLY_HEADER for month in range(1, 13)
刚发现yield from 结构,在我看来这有点像反向的yield,而不是从生成器中获取对象,您插入/将对象发送到生成器。喜欢: def foo(): while True:
考虑以下代码: def mygen(): yield (yield 1) a = mygen() print(next(a)) print(next(a)) 输出产量: 1 None 解释器
Guido van Rossum,在 2014 年关于 Tulip/Asyncio 的演讲中 shows the slide : Tasks vs coroutines Compare: res =
谁能帮我理解“yield self”和“yield”的区别? class YieldFirstLast attr_accessor :first, :last def initiali
这是我目前使用 Laravel 5 实现的 Open Graph 标签: app.blade.php @yield('title') page.blade.php @extends('app'
在 Tornado 中,我们通常会编写如下代码来异步调用函数: class MainHandler(tornado.web.RequestHandler): @tornado.gen.coro
本文整理了Java中aQute.bnd.indexer.analyzers.Yield.yield()方法的一些代码示例,展示了Yield.yield()的具体用法。这些代码示例主要来源于Github
我们有超过 100 个共同基金的每日返回,我们希望将这些返回转换为月度返回。每月返回不应是每个月的平均值,而是每个月末的资金返回。基金在不同的时间点开始和结束,它们需要自己保留(不是每个月的共同基金
如何实现 C# yield return使用 Scala 延续?我希望能够编写 Scala Iterator s 风格相同。在 this Scala news post 的评论中有刺伤,但它不起作用(
我是一名优秀的程序员,十分优秀!