Create XML Nodes based on XPath?

后端 未结 12 593
囚心锁ツ
囚心锁ツ 2020-11-27 15:36

Does anyone know of an existing means of creating an XML hierarchy programatically from an XPath expression?

For example if I have an XML fragment such as:

12条回答
  •  醉梦人生
    2020-11-27 15:59

    Here is a enhanced RegEx based on Mark Miller's code

    /([\w]+)(?:(?:[\[])(@|)([\w]+)(?:([!=<>]+)(?:(?:(?:')([^']+)(?:'))|([^']+))|)(?:[]])|)|([.]+))
    
    Group 1: Node name
    Group 2: @ (or Empty, for non attributes)
    Group 3: Attribute Key
    Group 4: Attribute Value (if string)
    Group 5: Attribute Value (if number)
    Group 6: .. (dots, one or more)
    

提交回复
热议问题