[英]Get element by its attribute value?
Is it possible to select/get an element by its attribute value? 是否可以通过其属性值选择/获取元素? So in my example below, can I select one of the elements based on the name attribute using the LibGDX XmlReader?
因此,在下面的示例中,我可以使用LibGDX XmlReader根据名称属性选择元素之一吗?
<root>
<element name="foo"/>
<element name="bar"/>
</root>
To clarify, I want to access the element directly if that is even possible. 为了澄清,我什至想直接访问该元素。 Not like below:
不像下面这样:
for (XmlReader.Element e : root.getChildrenByName("element")
{
if (e.getAttribute("name").Equals("foo"))
{
//Do stuff.
}
}
Reason for this is my coding flow first needs to work one element, then do more stuff independently of this element/xml. 原因是我的编码流程首先需要工作一个元素,然后独立于此元素/ xml做更多的事情。 Then when done I need to get another element so I need to iterate over many elements again and repeat that until done.
然后,完成后,我需要获取另一个元素,因此需要再次遍历许多元素,然后重复进行直到完成。 I wish I had more control over the produced XML files so I could just give them their own element name;
我希望对生成的XML文件有更多的控制权,所以我可以给它们指定自己的元素名称; these XML files are a nightmare.
这些XML文件是一场噩梦。
您可以为此使用getChildrenByName() 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.