我正在尝试从 onix 文件中读取并将信息保存到 mysql 数据库中。
我能够阅读标题、国家代码、isbn 和其他字段,但由于某些奇怪的原因,我无法得到简短的描述。
简短的描述字段<d102><d104>
嵌入在 html 文本中,当我尝试从它读取而不进行任何更改时,它不起作用,如果我尝试将其保存为字符串也会这样做。
在数据库上,我在表 shortdescription varchar(70) 中创建了一个字段,而且我起初还认为如果我增加它允许存储“varchar(70)”的数量,这无济于事!
这是我正在尝试阅读的 onix 提要的一部分
<othertext>
<d102>01</d102>
<d104><![CDATA[A Course in Behavioral Economics is a concise and reader-friendly
introduction to one of the most influential areas of economics today. Covering all core areas of the subject, the book requires no advanced mathematics and is full of examples, exercises, and problems drawn from the fields of economics, management, marketing, political science, and public policy, among others. It is an ideal first textbook for students coming to behavioral economics from a wide range of disciplines, and would also appeal to the general reader looking for a thorough and readable introduction to the subject.
Available to lecturers: access to an Instructor's Manual at www.palgrave.com/economics/angner, containing a sample syllabus,
instructor guide, sample handouts and examinations, and PowerPoint slides.]]></d104>
</othertext>
我尝试使用下面的代码,同样的理论适用于获取 isbn 等:
Function HandleTagName(name as String) as XName
Select Case name
Case "d104", "text"
If ShortName Then
Return "d104"
Else
Return "text"
End If
end select
end function
dim xmlDoc as XDocument
dim xr as XmlTextReader = new XmlTextReader(Server.MapPath(ThisBook.FromFile))
xr.Namespaces = false
dim document as XmlDocument = new XmlDocument()
document.Load(xr)
xr.close()
if not document("ONIXmessage") is Nothing then
Dim attrColl as XmlAttributeCollection = document("ONIXmessage").Attributes
attrColl.RemoveAll()
end if
xmlDoc = XDocument.Parse(document.OuterXML)
Dim Products As IEnumerable(Of XElement)
if xmlDoc.DocumentType is Nothing then
ShortName = True
else
if instr(xmlDoc.DocumentType.ToString(), "/short") then
ShortName = True
end if
end if
Products = from product in xmlDoc.Root.Descendants(HandleTagName("Product"))
For Each ThisOtherText In product.Elements(HandleTagName("OtherText"))
If ThisOtherText.Element(HandleTagName("TextTypeCode")) = "02" Then
If ThisBook.shortDescription = "" Then
' if you say
' dim xxx as string = "test"
' ThisBook.shortDescription = xxx
ThisBook.shortDescription = ThisOtherText.Element(HandleTagName("Text"))
End if
End If
Next
我不确定这是我在代码中做的不对还是与我在数据库上声明简短描述的方式有关