github.com/avicd/go-utilx@v0.1.0/xmlx/xpath_test.go (about) 1 package xmlx 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func TestCompile(t *testing.T) { 9 xml := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 10 "<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\"\n" + 11 " \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">\n" + 12 "<mapper namespace=\"MapperBuilder\">\n" + 13 " <sql id=\"sometable\">\n" + 14 " ${prefix}Table\n" + 15 " </sql>\n" + 16 "\n" + 17 " <sql id=\"someinclude-t2\">\n" + 18 " from\n" + 19 " <include refid=\"${include_target}\"/>\n" + 20 " </sql>\n" + 21 "\n" + 22 " <select id=\"select\" resultType=\"map\">\n" + 23 " select\n" + 24 " field1, field2, field3\n" + 25 "\n" + 26 " <sql id=\"someinclude\">\n" + 27 " from\n" + 28 " <include refid=\"${include_target}\"/>\n" + 29 " </sql>\n" + 30 " <include refid=\"someinclude\">\n" + 31 " <property name=\"prefix\" value=\"Some\"/>\n" + 32 " <property name=\"include_target\" value=\"sometable\"/>\n" + 33 " </include>\n" + 34 " <sql id=\"someinclude-s2\">\n" + 35 " from\n" + 36 " <include refid=\"${include_target}\"/>\n" + 37 " </sql>\n" + 38 " </select>\n" + 39 " <sql id=\"someinclude-t3\">\n" + 40 " from\n" + 41 " <include refid=\"${include_target}\"/>\n" + 42 " </sql>\n" + 43 "</mapper>" 44 xml1 := "<sml><sss/><sdfsdfds/></sml>" 45 node, _ := Parse(strings.NewReader(xml)) 46 node, _ = Parse(strings.NewReader(xml1)) 47 s := node.FindOne("//sss") 48 s.Remove() 49 println(s) 50 }