English 中文(简体)
如何获得xml 项目。 即便不存在“要素”的价值?
原标题:How to get xmlItem.Value even if Element does not exist?

我先从Xml和vb.net开始,我xml想这样做:

<?xml version="1.0" encoding="UTF-8"?>
<Steps>
  <X cmd="Message">
    <Message>Hello World</Message>
  </X>
  <X cmd="Message">
    <Message>Hello World2</Message>
    <Title>Cool Message</Title>
  </X>
</Steps>

我列举了整个xml,并且能够以我的方法之一获得此类物品:

Function showmsg(ByVal X As XmlElement)
Dim xTitle as String = X.Item("Title").innerText
Dim xMessage as String = X.Item("Message").innerText
MsgBox(xMessage, , xTitle)
End Function

因此,如果发现所有要素(配对、电传和带、标题和大体)的话,它就会发挥作用,但例如,如果“设计”、“所有权和”要素不被发现,我试图通过内部渠道获得。

是否有办法忽视这些错误,我只想得到一个空洞的价值,而不是任何错误。 也许有更好的办法这样做?

最佳回答

You ll need to check if

X.Item(“Title”) 无

before retrieving its value

另一种选择是,我们Try/Catch无视错误,但这样做会减缓你们的行踪并造成迷惑。

问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

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. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签