문제

I need to get a list of tags that contain a specific attribute. I am using DITA xml and I need to find out all tags that has a href attribute.

The problem here is that the attribute may be inside any tag so XPath will not work in this case. For example, an image tag may contain a href, a topicref tag may contain a href, and so on.

So I need to get a XmlNodeList (as returned by the getElementByTagName method). Ideally I need a method getElementByAttributeName that should return XmlNodeList.

도움이 되었습니까?

해결책

I might have misunderstood your problem here, but I think you could possibly use an XPath expression.

var nodes = doc.SelectNodes("//*[@href='pic1.jpg']");

The above should return all elements with href='pic1.jpg', where doc is the XmlDocument

다른 팁

If you're on C#, then the following approach might work for you:

XDocument document = XDocument.Load(xmlReader);
XAttribute xa = new XAttribute("href", "pic1.jpg");
var attrList = document.Descendants().Where (d => d.Attributes().Contains(xa));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top