12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package util
- import (
- "strings"
- )
- func ParseXmlNode(data string) (string, string, string) {
- a, b := findString(data, "<", ">")
- if a == -1 {
- return "", "", data
- }
- return ParseXmlNameNode(data, data[a:b])
- }
- func findString(data string, start string, end string) (int, int) {
- index1 := strings.Index(data, start)
- if index1 < 0 {
- return -1, -1
- }
- index2 := strings.Index(data, end)
- if index2 < 0 {
- return -1, -1
- }
- return index1 + len(start), index2
- }
- func ParseXmlNameNode(data string, name string) (string, string, string) {
- start := "<" + name + ">"
- end := "</" + name + ">"
- a, b := findString(data, start, end)
- if a == -1 {
- return "", "", data
- }
- a -= len(start)
- b += len(end)
- return name, data[a:b], data[b:]
- }
- func ParseXmlNameData(data string, name []string) string {
- var n string
- for i := 0; i < len(name); i++ {
- n, data, _ = ParseXmlNameNode(data, name[i])
- if n == "" {
- return ""
- }
- }
- a, b := findString(data, "<" + n + ">", "</" + n + ">")
- return data[a:b]
- }
|