当前位置: 首页>>代码示例>>Golang>>正文


Golang xml.NewDecoder函数代码示例

本文整理汇总了Golang中encoding/xml.NewDecoder函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDecoder函数的具体用法?Golang NewDecoder怎么用?Golang NewDecoder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewDecoder函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: query

func (ec2 *EC2) query(params map[string]string, resp interface{}) error {
	params["Version"] = "2013-02-01"
	params["Timestamp"] = timeNow().In(time.UTC).Format(time.RFC3339)
	endpoint, err := url.Parse(ec2.Region.EC2Endpoint)
	if err != nil {
		return err
	}
	if endpoint.Path == "" {
		endpoint.Path = "/"
	}
	sign(ec2.Auth, "GET", endpoint.Path, params, endpoint.Host)
	endpoint.RawQuery = multimap(params).Encode()
	if debug {
		log.Printf("get { %v } -> {\n", endpoint.String())
	}
	r, err := http.Get(endpoint.String())
	if err != nil {
		return err
	}
	defer r.Body.Close()

	if debug {
		dump, _ := httputil.DumpResponse(r, true)
		log.Printf("response:\n")
		log.Printf("%v\n}\n", string(dump))
	}
	if r.StatusCode != 200 {
		return buildError(r)
	}
	err = xml.NewDecoder(r.Body).Decode(resp)
	return err
}
开发者ID:rgarcia,项目名称:goamz,代码行数:32,代码来源:ec2.go

示例2: names

// Returns the root node of a tree of valid element names
func names(rdr io.Reader) *name {
	var n = new(name)

	ns := make(map[string]bool)

	decoder := xml.NewDecoder(rdr)
	decoder.Strict = false

	for tok, err := decoder.RawToken(); err != io.EOF; tok, err = decoder.RawToken() {
		// if it breaks, try again!
		if err != nil {
			decoder = xml.NewDecoder(rdr)
			decoder.Strict = false
			continue
		}
		switch el := tok.(type) {
		case xml.StartElement:
			if _, ok := ns[el.Name.Local]; !ok {
				ns[el.Name.Local] = false
			}
		case xml.EndElement:
			if _, ok := ns[el.Name.Local]; ok {
				ns[el.Name.Local] = true
			}
		}
	}
	for k, v := range ns {
		if v {
			n.add([]byte(k))
		}
	}
	// add the XML declaration to the list of valid names (a bit of a hack)
	n.add([]byte("?xml version=\"1.0\"?"))
	return n
}
开发者ID:richardlehane,项目名称:xmltool,代码行数:36,代码来源:fix.go

示例3: respIsOk

func respIsOk(sVueResp *SVUEResponse, expectedElement string) (*xml.Decoder, error) {
	d := xml.NewDecoder(strings.NewReader(sVueResp.Result))

TokenLoop:
	for {
		t, err := d.Token()

		if err == io.EOF {
			return nil, SVUEError{
				OrigError: err,
				Code:      DecodingError,
			}
		}

		if _t, ok := t.(xml.StartElement); ok {
			switch _t.Name.Local {
			case expectedElement:
				break TokenLoop
			case "RT_ERROR":
				return nil, decodeRespError(sVueResp)
			default:
				continue TokenLoop
			}
		} else {
			continue
		}
	}

	return xml.NewDecoder(strings.NewReader(sVueResp.Result)), nil
}
开发者ID:jac0,项目名称:govue,代码行数:30,代码来源:decode_xml.go

示例4: loadConfig

func loadConfig(dirName string) (*objects.Core, error) {
	dir, err := os.Open(os.ExpandEnv(dirName))
	if err != nil {
		return nil, err
	}
	s, err := dir.Stat()
	if err != nil {
		return nil, err
	}
	cfg := &objects.Core{}
	if !s.IsDir() {
		decoder := xml.NewDecoder(dir)
		err = decoder.Decode(&cfg)
		return cfg, err
	}

	files, err := dir.Readdir(-1)
	if err != nil {
		return nil, err
	}
	sort.Sort(FilesByName(files))
	for _, fInfo := range files {
		file, err := os.Open(dirName + fInfo.Name())
		if err != nil {
			return nil, err
		}
		decoder := xml.NewDecoder(file)
		err = decoder.Decode(&cfg)
		if err != nil {
			return nil, fmt.Errorf("Decoding %s: %s", fInfo.Name(), err.Error())
		}
	}

	return cfg, nil
}
开发者ID:daemonl,项目名称:informer,代码行数:35,代码来源:informer.go

示例5: startStream

// startStream will start a new XML decoder for the connection, signal the start of a stream to the server and verify that the server has
// also started the stream; if o.Debug is true, startStream will tee decoded XML data to stderr.  The features advertised by the server
// will be returned.
func (c *Client) startStream(o *Options, domain string) (*streamFeatures, error) {
	if o.Debug {
		c.p = xml.NewDecoder(tee{c.conn, os.Stderr})
	} else {
		c.p = xml.NewDecoder(c.conn)
	}

	_, err := fmt.Fprintf(c.conn, "<?xml version='1.0'?>\n"+
		"<stream:stream to='%s' xmlns='%s'\n"+
		" xmlns:stream='%s' version='1.0'>\n",
		xmlEscape(domain), nsClient, nsStream)
	if err != nil {
		return nil, err
	}

	// We expect the server to start a <stream>.
	se, err := nextStart(c.p)
	if err != nil {
		return nil, err
	}
	if se.Name.Space != nsStream || se.Name.Local != "stream" {
		return nil, fmt.Errorf("expected <stream> but got <%v> in %v", se.Name.Local, se.Name.Space)
	}

	// Now we're in the stream and can use Unmarshal.
	// Next message should be <features> to tell us authentication options.
	// See section 4.6 in RFC 3920.
	f := new(streamFeatures)
	if err = c.p.DecodeElement(f, nil); err != nil {
		return f, errors.New("unmarshal <features>: " + err.Error())
	}
	return f, nil
}
开发者ID:marswang,项目名称:go-xmpp,代码行数:36,代码来源:xmpp.go

示例6: processIQ

func processIQ(stanza *xmpp.ClientIQ) interface{} {
	buf := bytes.NewBuffer(stanza.Query)
	parser := xml.NewDecoder(buf)
	token, _ := parser.Token()
	if token == nil {
		return nil
	}
	startElem, ok := token.(xml.StartElement)
	if !ok {
		return nil
	}
	switch startElem.Name.Local {
	case "update_contacts":
		var contacts ConfigContacts
		if err := xml.NewDecoder(bytes.NewBuffer(stanza.Query)).Decode(&contacts); err != nil {
			log.Print("Failed to parse IQ for ConfigContacts")
			return nil
		}
		for _, contact := range contacts.Contacts {
			handleContact(contact)
		}
		return xmpp.EmptyReply{}
	default:
		log.Print("Unknown IQ: ", startElem.Name.Local)
	}

	return nil
}
开发者ID:kissthink,项目名称:go-xmppclient,代码行数:28,代码来源:main.go

示例7: TestReadRowsFromSheetWithMergeCells

func (l *LibSuite) TestReadRowsFromSheetWithMergeCells(c *C) {
	var sharedstringsXML = bytes.NewBufferString(`
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="3" uniqueCount="3">
  <si>
    <t>Value A</t>
  </si>
  <si>
    <t>Value B</t>
  </si>
  <si>
    <t>Value C</t>
  </si>
</sst>
`)
	var sheetxml = bytes.NewBufferString(`
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">
  <sheetViews>
    <sheetView workbookViewId="0"/>
  </sheetViews>
  <sheetFormatPr customHeight="1" defaultColWidth="17.29" defaultRowHeight="15.0"/>
  <cols>
    <col customWidth="1" min="1" max="6" width="14.43"/>
  </cols>
  <sheetData>
    <row r="1" ht="15.75" customHeight="1">
      <c r="A1" s="1" t="s">
        <v>0</v>
      </c>
    </row>
    <row r="2" ht="15.75" customHeight="1">
      <c r="A2" s="1" t="s">
        <v>1</v>
      </c>
      <c r="B2" s="1" t="s">
        <v>2</v>
      </c>
    </row>
  </sheetData>
  <mergeCells count="1">
    <mergeCell ref="A1:B1"/>
  </mergeCells>
  <drawing r:id="rId1"/>
</worksheet>`)
	worksheet := new(xlsxWorksheet)
	err := xml.NewDecoder(sheetxml).Decode(worksheet)
	c.Assert(err, IsNil)
	sst := new(xlsxSST)
	err = xml.NewDecoder(sharedstringsXML).Decode(sst)
	c.Assert(err, IsNil)
	file := new(File)
	file.referenceTable = MakeSharedStringRefTable(sst)
	sheet := new(Sheet)
	rows, _, _, _ := readRowsFromSheet(worksheet, file, sheet)
	row := rows[0] //
	cell1 := row.Cells[0]
	c.Assert(cell1.HMerge, Equals, 1)
	c.Assert(cell1.VMerge, Equals, 0)
}
开发者ID:thieupham-wf,项目名称:xlsx,代码行数:60,代码来源:lib_test.go

示例8: CreateQueue

func (s *SQSRequest) CreateQueue(queueName string, options map[string]string) (*QueueURLResponse, error) {
	params := map[string]string{
		"Action":    "CreateQueue",
		"QueueName": queueName,
	}

	count := 1
	for name, value := range options {
		params[fmt.Sprintf("Attribute.%d.Name", count)] = name
		params[fmt.Sprintf("Attribute.%d.Value", count)] = value
		count++
	}

	reader, err := s.makeSQSAdminRequest(params)
	if err != nil {
		er := new(ErrorResponse)
		xml.NewDecoder(reader).Decode(er)
		log.Println(er)
		return nil, err
	}

	qur := new(QueueURLResponse)
	if err = xml.NewDecoder(reader).Decode(qur); err != nil {
		return nil, err
	}

	return qur, nil
}
开发者ID:neurodrone,项目名称:aws-sqs,代码行数:28,代码来源:sqs.go

示例9: call

func (v *Vsphere) call(body string, dst interface{}) error {
	buf := new(bytes.Buffer)
	buf.WriteString(soapPre)
	buf.WriteString(body)
	buf.WriteString(soapPost)
	req, err := http.NewRequest("POST", v.url.String(), buf)
	if err != nil {
		return err
	}
	for k, v := range v.header {
		req.Header[k] = v
	}
	for _, c := range v.cookies.Cookies(v.url) {
		req.AddCookie(c)
	}
	resp, err := v.client.Do(req)
	if err != nil {
		return err
	}
	v.cookies.SetCookies(v.url, resp.Cookies())
	defer resp.Body.Close()
	if resp.StatusCode == 500 {
		var e Error
		if err := xml.NewDecoder(resp.Body).Decode(&e); err != nil {
			return fmt.Errorf("vsphere: bad response, could not decode error: %v", err)
		}
		return e
	} else if resp.StatusCode != 200 {
		return fmt.Errorf("vsphere: bad status code %v", resp.Status)
	}
	if dst != nil {
		return xml.NewDecoder(resp.Body).Decode(dst)
	}
	return nil
}
开发者ID:eswdd,项目名称:bosun,代码行数:35,代码来源:vsphere.go

示例10: FindOrganisations

func (v *VCloudSession) FindOrganisations(max_page_size, max_pages int) (Orgs []*Organisation, err error) {

	if max_page_size <= 0 {
		max_page_size = 1
	}

	if max_pages <= 0 {
		max_pages = 1
	}

	for i := 1; i <= max_pages; i++ {
		page := &OrgReferences{}
		uri := fmt.Sprintf("/api/query?type=organization&format=references&pageSize=%v&page=%v", max_page_size, i)
		r, err := v.Get(uri)

		if err != nil {
			continue
		}

		defer r.Body.Close()

		if r.StatusCode == 400 {
			break
		}

		_ = xml.NewDecoder(r.Body).Decode(page)

		for _, record := range page.Records {
			u, _ := url.Parse(record.Href)
			r, err := v.Get(u.Path)

			if err != nil {
				continue
			}

			defer r.Body.Close()

			if r.StatusCode != 200 {
				continue
			}

			new_org := &Organisation{}
			_ = xml.NewDecoder(r.Body).Decode(new_org)

			for k, val := range new_org.Links {
				u, _ := url.Parse(val.Href)
				new_org.Links[k].Href = u.Path
			}

			Orgs = append(Orgs, new_org)
		}
	}

	if len(Orgs) <= 0 {
		return Orgs, errors.New("No organisations returned.")
	} else {
		return Orgs, nil
	}
}
开发者ID:jfroche,项目名称:vCloudOSLicenses,代码行数:59,代码来源:search.go

示例11: TestReadRowsFromSheetWithHiddenColumn

func (l *LibSuite) TestReadRowsFromSheetWithHiddenColumn(c *C) {
	var sharedstringsXML = bytes.NewBufferString(`
		<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
		<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
		    <si><t>This is a test.</t></si>
		    <si><t>This should be invisible.</t></si>
		</sst>`)
	var sheetxml = bytes.NewBufferString(`
		<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
		<worksheet xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main"
		    xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main"
		    xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
			<sheetViews><sheetView workbookViewId="0"/>
			</sheetViews>
			<sheetFormatPr customHeight="1" defaultColWidth="14.43" defaultRowHeight="15.75"/>
			<cols>
				<col hidden="1" max="2" min="2"/>
			</cols>
		    <sheetData>
		        <row r="1">
		            <c r="A1" s="1" t="s"><v>0</v></c>
		            <c r="B1" s="1" t="s"><v>1</v></c>
		        </row>
		    </sheetData><drawing r:id="rId1"/></worksheet>`)
	worksheet := new(xlsxWorksheet)
	err := xml.NewDecoder(sheetxml).Decode(worksheet)
	c.Assert(err, IsNil)
	sst := new(xlsxSST)
	err = xml.NewDecoder(sharedstringsXML).Decode(sst)
	c.Assert(err, IsNil)
	file := new(File)
	file.referenceTable = MakeSharedStringRefTable(sst)
	sheet := new(Sheet)
	rows, _, maxCols, maxRows := readRowsFromSheet(worksheet, file, sheet)
	c.Assert(maxRows, Equals, 1)
	c.Assert(maxCols, Equals, 2)
	row := rows[0]
	c.Assert(row.Sheet, Equals, sheet)
	c.Assert(len(row.Cells), Equals, 2)

	cell1 := row.Cells[0]
	c.Assert(cell1.Type(), Equals, CellTypeString)
	if val, err := cell1.String(); err != nil {
		c.Error(err)
	} else {
		c.Assert(val, Equals, "This is a test.")
	}
	c.Assert(cell1.Hidden, Equals, false)

	cell2 := row.Cells[1]
	c.Assert(cell2.Type(), Equals, CellTypeString)
	if val, err := cell2.String(); err != nil {
		c.Error(err)
	} else {
		c.Assert(val, Equals, "This should be invisible.")
	}
	c.Assert(cell2.Hidden, Equals, true)
}
开发者ID:tealeg,项目名称:xlsx,代码行数:58,代码来源:lib_test.go

示例12: UnmarshalStream

func UnmarshalStream(url string, reader io.Reader) (feed *Feed, err error) {
	// Read the stream into memory (we'll need to parse it twice)
	var contentReader *bytes.Reader
	var content []byte
	if content, err = ioutil.ReadAll(reader); err == nil {
		contentReader = bytes.NewReader(content)

		genericFeed := GenericFeed{}

		decoder := xml.NewDecoder(contentReader)
		decoder.CharsetReader = charset.NewReader

		// First pass - parse the feed as-is
		if err = decoder.Decode(&genericFeed); err != nil {
			// Error - check for invalid entities and correct as appropriate
			if fixed, fixedContent := fixEntities(content); fixed {
				// At least one replacement was made. Retry
				contentReader = bytes.NewReader(fixedContent)
				decoder = xml.NewDecoder(contentReader)
				decoder.CharsetReader = charset.NewReader

				// Try decoding again
				err = decoder.Decode(&genericFeed)
			}
		}

		if err != nil {
			return
		}

		var xmlFeed FeedMarshaler
		if genericFeed.XMLName.Space == "http://www.w3.org/1999/02/22-rdf-syntax-ns#" && genericFeed.XMLName.Local == "RDF" {
			xmlFeed = &rss1Feed{}
		} else if genericFeed.XMLName.Local == "rss" {
			xmlFeed = &rss2Feed{}
		} else if genericFeed.XMLName.Space == "http://www.w3.org/2005/Atom" && genericFeed.XMLName.Local == "feed" {
			xmlFeed = &atomFeed{}
		} else {
			err = errors.New("Unsupported type of feed (" +
				genericFeed.XMLName.Space + ":" + genericFeed.XMLName.Local + ")")
			return
		}

		contentReader.Seek(0, 0)

		decoder = xml.NewDecoder(contentReader)
		decoder.CharsetReader = charset.NewReader

		if err = decoder.Decode(xmlFeed); err == nil {
			if feed, err = xmlFeed.Marshal(); err == nil {
				feed.URL = url
			}
		}
	}

	return
}
开发者ID:pokebyte,项目名称:Gofr,代码行数:57,代码来源:feed.go

示例13: TestReadRowsFromSheetWithTrailingEmptyCells

func (l *LibSuite) TestReadRowsFromSheetWithTrailingEmptyCells(c *C) {
	var row *Row
	var cell1, cell2, cell3, cell4 *Cell
	var sharedstringsXML = bytes.NewBufferString(`
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="4" uniqueCount="4"><si><t>A</t></si><si><t>B</t></si><si><t>C</t></si><si><t>D</t></si></sst>`)
	var sheetxml = bytes.NewBufferString(`
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1:D8"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="A7" sqref="A7"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="15"/><sheetData><row r="1" spans="1:4"><c r="A1" t="s"><v>0</v></c><c r="B1" t="s"><v>1</v></c><c r="C1" t="s"><v>2</v></c><c r="D1" t="s"><v>3</v></c></row><row r="2" spans="1:4"><c r="A2"><v>1</v></c></row><row r="3" spans="1:4"><c r="B3"><v>1</v></c></row><row r="4" spans="1:4"><c r="C4"><v>1</v></c></row><row r="5" spans="1:4"><c r="D5"><v>1</v></c></row><row r="6" spans="1:4"><c r="C6"><v>1</v></c></row><row r="7" spans="1:4"><c r="B7"><v>1</v></c></row><row r="8" spans="1:4"><c r="A8"><v>1</v></c></row></sheetData><pageMargins left="0.7" right="0.7" top="0.78740157499999996" bottom="0.78740157499999996" header="0.3" footer="0.3"/></worksheet>
`)
	worksheet := new(xlsxWorksheet)
	err := xml.NewDecoder(sheetxml).Decode(worksheet)
	c.Assert(err, IsNil)

	sst := new(xlsxSST)
	err = xml.NewDecoder(sharedstringsXML).Decode(sst)
	c.Assert(err, IsNil)

	file := new(File)
	file.referenceTable = MakeSharedStringRefTable(sst)
	sheet := new(Sheet)
	rows, _, maxCol, maxRow := readRowsFromSheet(worksheet, file, sheet)
	c.Assert(maxCol, Equals, 4)
	c.Assert(maxRow, Equals, 8)

	row = rows[0]
	c.Assert(row.Sheet, Equals, sheet)
	c.Assert(len(row.Cells), Equals, 4)

	cell1 = row.Cells[0]
	c.Assert(cell1.Value, Equals, "A")

	cell2 = row.Cells[1]
	c.Assert(cell2.Value, Equals, "B")

	cell3 = row.Cells[2]
	c.Assert(cell3.Value, Equals, "C")

	cell4 = row.Cells[3]
	c.Assert(cell4.Value, Equals, "D")

	row = rows[1]
	c.Assert(row.Sheet, Equals, sheet)
	c.Assert(len(row.Cells), Equals, 4)

	cell1 = row.Cells[0]
	c.Assert(cell1.Value, Equals, "1")

	cell2 = row.Cells[1]
	c.Assert(cell2.Value, Equals, "")

	cell3 = row.Cells[2]
	c.Assert(cell3.Value, Equals, "")

	cell4 = row.Cells[3]
	c.Assert(cell4.Value, Equals, "")
}
开发者ID:thieupham-wf,项目名称:xlsx,代码行数:57,代码来源:lib_test.go

示例14: TestRowNotOverwrittenWhenFollowedByEmptyRow

func (l *LibSuite) TestRowNotOverwrittenWhenFollowedByEmptyRow(c *C) {
	sheetXML := bytes.NewBufferString(`
	<?xml version="1.0" encoding="UTF-8"?>
	<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">
		<sheetViews>
			<sheetView workbookViewId="0" />
		</sheetViews>
		<sheetFormatPr customHeight="1" defaultColWidth="14.43" defaultRowHeight="15.75" />
		<sheetData>
			<row r="2">
				<c r="A2" t="str">
					<f t="shared" ref="A2" si="1">RANDBETWEEN(1,100)</f>
					<v>66</v>
				</c>
			</row>
			<row r="3">
				<c r="A3" t="str">
					<f t="shared" ref="A3" si="2">RANDBETWEEN(1,100)</f>
					<v>30</v>
				</c>
			</row>
			<row r="4">
				<c r="A4" t="str">
					<f t="shared" ref="A4" si="3">RANDBETWEEN(1,100)</f>
					<v>75</v>
				</c>
			</row>
			<row r="7">
				<c r="A7" s="1" t="str">
					<f t="shared" ref="A7" si="4">A4/A2</f>
					<v>1.14</v>
				</c>
			</row>
		</sheetData>
		<drawing r:id="rId1" />
	</worksheet>
	`)

	sharedstringsXML := bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>`)

	worksheet := new(xlsxWorksheet)
	xml.NewDecoder(sheetXML).Decode(worksheet)

	sst := new(xlsxSST)
	xml.NewDecoder(sharedstringsXML).Decode(sst)

	file := new(File)
	file.referenceTable = MakeSharedStringRefTable(sst)

	sheet := new(Sheet)
	rows, _, _, _ := readRowsFromSheet(worksheet, file, sheet)
	cells := rows[3].Cells

	c.Assert(cells, HasLen, 1)
	c.Assert(cells[0].Value, Equals, "75")
}
开发者ID:thieupham-wf,项目名称:xlsx,代码行数:56,代码来源:lib_test.go

示例15: TestBucketMultipartList

func (s *MyAPIDonutCacheSuite) TestBucketMultipartList(c *C) {
	request, err := http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/bucketmultipartlist", bytes.NewBufferString(""))
	c.Assert(err, IsNil)
	setDummyAuthHeader(request)

	client := http.Client{}
	response, err := client.Do(request)
	c.Assert(err, IsNil)
	c.Assert(response.StatusCode, Equals, 200)

	request, err = http.NewRequest("POST", testAPIDonutCacheServer.URL+"/bucketmultipartlist/object?uploads", bytes.NewBufferString(""))
	c.Assert(err, IsNil)
	setDummyAuthHeader(request)

	response, err = client.Do(request)
	c.Assert(response.StatusCode, Equals, http.StatusOK)

	decoder := xml.NewDecoder(response.Body)
	newResponse := &api.InitiateMultipartUploadResult{}

	err = decoder.Decode(newResponse)
	c.Assert(err, IsNil)
	c.Assert(len(newResponse.UploadID) > 0, Equals, true)
	uploadID := newResponse.UploadID

	request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=1", bytes.NewBufferString("hello world"))
	c.Assert(err, IsNil)
	setDummyAuthHeader(request)

	response1, err := client.Do(request)
	c.Assert(err, IsNil)
	c.Assert(response1.StatusCode, Equals, http.StatusOK)

	request, err = http.NewRequest("PUT", testAPIDonutCacheServer.URL+"/bucketmultipartlist/object?uploadId="+uploadID+"&partNumber=2", bytes.NewBufferString("hello world"))
	c.Assert(err, IsNil)
	setDummyAuthHeader(request)

	response2, err := client.Do(request)
	c.Assert(err, IsNil)
	c.Assert(response2.StatusCode, Equals, http.StatusOK)

	request, err = http.NewRequest("GET", testAPIDonutCacheServer.URL+"/bucketmultipartlist?uploads", nil)
	c.Assert(err, IsNil)
	setDummyAuthHeader(request)

	response3, err := client.Do(request)
	c.Assert(err, IsNil)
	c.Assert(response3.StatusCode, Equals, http.StatusOK)

	decoder = xml.NewDecoder(response3.Body)
	newResponse3 := &api.ListMultipartUploadsResponse{}
	err = decoder.Decode(newResponse3)
	c.Assert(err, IsNil)
	c.Assert(newResponse3.Bucket, Equals, "bucketmultipartlist")
}
开发者ID:bosky101,项目名称:minio,代码行数:55,代码来源:api_donut_cache_test.go


注:本文中的encoding/xml.NewDecoder函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。