0
<Restaurant>
   <firstFloor type="chinese" price="High" type="Indian">
   <firstFloor type="chinese" price="High">
</Restaurant>

I am trying to find the number of duplicate attributes inside a single node using xpath 1.0.

Can anyone tell a method to find that type has been assigned two times in the first firstFloor node? Existing solutions does not provide solution to find the duplicate attributes within the same node (Compares sibling nodes)?

I am expecting for a xpath 1.0 answer however xpath 2.0 answer is also acceptable.

Thanks in advance.

Andersson
  • 51,635
  • 17
  • 77
  • 129
Nilucshan Siva
  • 433
  • 7
  • 16
  • 1
    What you did so far? – yılmaz Feb 27 '18 at 10:33
  • 1
    This XML is not even valid... How is it generated? Is this under your control? – Shnugo Feb 27 '18 at 11:14
  • As per XML specification we cant make duplicate attribute in same element. check well formation of the XML. – Amrendra Kumar Feb 27 '18 at 12:07
  • Actually i am implementing a tool to find such violations in a xml file. More clearly i can say i am trying to implement following rule using xpath. https://github.com/yaniswang/HTMLHint/wiki/attr-no-duplication – Nilucshan Siva Feb 27 '18 at 13:05
  • 1
    @NilucshanSiva In order to *use `XPath`*, you need a well-formed XML. No tool, capable of `XPath`, will accept your input. This is a string, which *looks like XML* - but it is not... There are tolerant parsers out there... In most cases such issues should not occur, so the producer of this XML has to fix this problem. – Shnugo Feb 27 '18 at 13:17
  • I suspect the ill-formedness is simply a typo and the firstFloor tags should have been self-closing. But the fact that the question has been closed as a duplicate on those grounds hopefully means the OP will take more care in future. – Michael Kay Feb 27 '18 at 14:31

1 Answers1

1

No XML tool, including XPath, can help you with your data, because your data is not XML.

  • XML does not allow two attributes with the same name on a single element.
  • XML requires all elements to be self-closing or have end tags.

See also:

  1. How to parse invalid (bad / not well-formed) XML?
  2. Explanation of Well-formed
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Thank you. I am actually trying to implement one of the rule in https://github.com/yaniswang/HTMLHint/wiki/attr-no-duplication using xpath 1.0. Can you suggest any way to implement this feature only using xpath? – Nilucshan Siva Feb 27 '18 at 13:08
  • 1
    You've completely missed, or chosen to ignore, the entire point of this answer. Re-read it more carefully. Thanks. – kjhughes Feb 27 '18 at 13:35
  • 1
    @NilucshanSiva As pointed out above, **you cannot *use XPath* if the input is not *well-formed***. – Shnugo Feb 27 '18 at 13:38