English 中文(简体)
重新选择使用XPath的孩子?
原标题:Recursively select children node using XPath recursively?
  • 时间:2011-11-22 06:50:50
  •  标签:
  • c#
  • xpath

考虑到以下十项法律:

<Checks>
   <IsSomethingCheck Param="1"/>
   <IsSomeoneCheck Param2="2"/>
   <Checks Operator="Or">
       <IsAnythingCheck Param3="3"/>
   </Checks>
</Checks>

我怎样回击<密码>中的孩子?

下面的法典适用于最外生儿童,但停止了处理大多数内身儿童的工作(内部编码部分)。

protected override void InitializePlugin(XmlElement xmlElement)
{
    Enum.TryParse(xmlElement.GetAttribute("Operator"), out _operator);

    XPathNodeIterator nav = xmlElement.CreateNavigator().Select("Checks/*");

    foreach (XPathNavigator checkNode in nav)
    {
        if (_checksLookup.ContainsKey(checkNode.Name))
        {
            Type checkType = _checksLookup[checkNode.Name];
            Check check = Activator.CreateInstance(checkType) as Check;
            check.Initialize(checkNode.OuterXml);
            Checks.Add(check);
        }
    }    
}

PS:这一方法的XmlElement预计会得到XML中整个<代码>Checks部分。

问题回答

创立! XPath expression should be /CheckManager/* not CheckManager/*.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签