我试图解组下面的代码,底部有go操场 . data.DocumentType总是返回0并且应该返回内部xml 4.有人可以告诉我为什么这不起作用?
package main
import (
"encoding/xml"
"fmt"
)
type doc struct {
XMLName xml.Name `xml:"ownershipDocument"`
SchemaVersion string `xml:",innerxml"`
DocumentType int `xml:",innerxml"`
}
func main() {
var Data doc
xml.Unmarshal([]byte(VV), &Data)
fmt.Println(Data.DocumentType)
}
const VV = `<?xml version="1.0"?>
<ownershipDocument>
<schemaVersion>X0306</schemaVersion>
<documentType>4</documentType>
<periodOfReport>2015-11-18</periodOfReport>
<issuer>
<issuerCik>0000820081</issuerCik>
<issuerName>CAMBREX CORP</issuerName>
<issuerTradingSymbol>CBM</issuerTradingSymbol>
</issuer>
<reportingOwner>
<reportingOwnerId>
<rptOwnerCik>0001227832</rptOwnerCik>
<rptOwnerName>KORB WILLIAM B</rptOwnerName>
</reportingOwnerId>
<reportingOwnerAddress>
<rptOwnerStreet1>1 MEADOWLANDS PLAZA</rptOwnerStreet1>
<rptOwnerStreet2></rptOwnerStreet2>
<rptOwnerCity>EAST RUTHERFORD</rptOwnerCity>
<rptOwnerState>NJ</rptOwnerState>
<rptOwnerZipCode>07073</rptOwnerZipCode>
<rptOwnerStateDescription></rptOwnerStateDescription>
</reportingOwnerAddress>
<reportingOwnerRelationship>
<isDirector>1</isDirector>
<isOfficer>0</isOfficer>
<isTenPercentOwner>0</isTenPercentOwner>
<isOther>0</isOther>
</reportingOwnerRelationship>
</reportingOwner>
<nonDerivativeTable>
<nonDerivativeTransaction>
<securityTitle>
<value>Common Stock</value>
</securityTitle>
<transactionDate>
<value>2015-11-18</value>
</transactionDate>
<transactionCoding>
<transactionFormType>4</transactionFormType>
<transactionCode>S</transactionCode>
<equitySwapInvolved>0</equitySwapInvolved>
</transactionCoding>
<transactionAmounts>
<transactionShares>
<value>10000</value>
</transactionShares>
<transactionPricePerShare>
<value>50.18</value>
<footnoteId id="F1"/>
</transactionPricePerShare>
<transactionAcquiredDisposedCode>
<value>D</value>
</transactionAcquiredDisposedCode>
</transactionAmounts>
<postTransactionAmounts>
<sharesOwnedFollowingTransaction>
<value>36562</value>
</sharesOwnedFollowingTransaction>
</postTransactionAmounts>
<ownershipNature>
<directOrIndirectOwnership>
<value>D</value>
</directOrIndirectOwnership>
<natureOfOwnership>
<value></value>
</natureOfOwnership>
</ownershipNature>
</nonDerivativeTransaction>
</nonDerivativeTable>
<footnotes>
<footnote id="F1">The price reported in Column 4 is a weighted average price. These shares were sold in multiple transactions at prices ranging from $50.00 to $50.58 inclusive. The reporting person undertakes to provide to Cambrex Corporation, any security holder of Cambrex Corporation, or the staff of the Securities and Exchange Commission, upon request, full information regarding the number of shares sold at each separate price within the range set forth in this Footnote 1 to this Form 4.</footnote>
</footnotes>
<remarks></remarks>
<ownerSignature>
<signatureName>Samantha Hanley for William B. Korb by POA</signatureName>
<signatureDate>2015-11-20</signatureDate>
</ownerSignature>
</ownershipDocument>`
2 回答
删除
DocumentType
上的innerxml
标记,并为其匹配(xml:"documentType"
) . 来自the xml library docs:您不需要存储未处理的XML . 您正在寻找该字段的值,因此您不需要该标记 .
Working version
*编辑:就此而言,
",innerxml"
标签也会打破SchemaVersion
字段 - 没有匹配的元素(因为SchemaVersion
是一个字符串),它存储整个文档 .