private MarcRecord(string strMarc) { this.ldr = new LDR(strMarc.Substring(0, LDR.LDRLength)); this.fields = new List<Field>(); string strAddress = strMarc.Substring(LDR.LDRLength, ldr.BaseAddress - LDR.LDRLength + 1); string strData = strMarc.Substring(ldr.BaseAddress); string[] strField = strData.Split(Field.FieldEnd); for (int i = 0; i < strAddress.Length / AddressItemLength; i++) { string addressItem = strAddress.Substring(i * AddressItemLength, AddressItemLength); string tag = addressItem.Substring(0, 3); Field fld; if (tag.Equals("-01") || tag.Equals("001") || tag.Equals("005")) { fld = new ControlField(tag, strField[i]); } else { fld = new DataField(tag, strField[i]); } fields.Add(fld); } }
/// <summary> /// 生成新的Marc的record记录 /// </summary> /// <param name="newLDR"></param> /// <returns></returns> public static MarcRecord NewRecord(string newLDR) { if (string.IsNullOrEmpty(newLDR)) return null; if (newLDR.Length < LDR.LDRLength) return null; LDR ldr = new LDR(newLDR); MarcRecord record = new MarcRecord(ldr); return record; }
private MarcRecord(LDR ldr) { this.ldr = ldr; this.fields = new List<Field>(); }
/// <summary> /// 由xml格式的marc生成record对象,marc的xml格式方案来自于TopEnginge /// </summary> /// <param name="xmlMarc"></param> /// <returns></returns> public static MarcRecord LoadFromXMlString(string xmlMarc) { XElement xe = XElement.Parse(xmlMarc); string strldr = xe.Element("header").Value; LDR ldr = new LDR(strldr); MarcRecord record = new MarcRecord(ldr); foreach(XElement fldxml in xe.Elements("field")) { Field fld; string tag = fldxml.Attribute("name").Value; if (tag.Equals("-01") || tag.Equals("001") || tag.Equals("005")) { fld = new ControlField(tag, fldxml.Value); } else { fld = new DataField(tag); string indicator = fldxml.Attribute("indicator") == null ? string.Empty : fldxml.Attribute("indicator").Value; foreach (XElement sfxml in fldxml.Elements("sf")) { ((DataField)fld).AddSubField(sfxml.Attribute("name").Value[0], sfxml.Value); } } record.AddField(fld); } return record; }