Example #1
0
        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);
            }
        }
Example #2
0
        /// <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;
        }