这是XElement
:Dim oTaget=
:
<target xmlns="urn:oasis:names:tc:xliff:document:1.2">
<mrk mtype="seg" mid="1082">■ <x id="8746" /><g id="8747">Store the product ./g></mrk>
<g id="8747">
<mrk mtype="seg" mid="1083">For this purpose</mrk>
</g>
</target>
我想要计数编号mrk
:
Dim sentenchild As IEnumerable(Of XElement)
sentenchild = oTaget.XPathSelectElements(dNS + ":mrk", namespaceManager)
Return sentenchild.Count
但结果= 1
如何统计mrk
的所有代码oTaget
?
谢谢大家。
答案 0 :(得分:1)
您的结果计数是一个,因为您设置的msg = input("Enter a word: ")
h = " "
half =" "
first = msg[0]
second = msg[1]
msg2 = "gg"
length = len(msg)
third = msg[2]
if first not in "aeiou":
if second != third:
print(msg.replace(msg[1], msg[1] * 10))
elif second == third:
msg2 = third * 6
msg3 = (msg.replace(msg[2], msg2))
msg4 = first + msg3[2:]
print(msg4)
else:
half = first * 10
msg10 = msg[1:length]
print((half) + msg10)
选择元素,这只会计算XPath
第一个子级别中的mrk
个元素。您必须递归迭代target
的所有子元素。
修改强>
VB.NET中的递归示例请参见:http://www.dotnetperls.com/recursion-vbnet
答案 1 :(得分:1)
使用.//element
模式返回上下文元素中所有元素:
sentenchild = oTaget.XPathSelectElements(".//" + dNS + ":mrk", namespaceManager)
引自XPath 1.0 spec # 2.5 Abbreviated Syntax:
.//para
选择上下文节点的para
元素后代
另一种方法是使用Descendants()
方法:
Dim dNS As XNamespace = "urn:oasis:names:tc:xliff:document:1.2"
sentenchild = oTaget.Descendants(dNS + "mrk")