Exemple #1
0
        private static void AddDateToValueNode(XmlNode valNode, string date)
        {
            string year = "", month = "", day = "";

            try
            {
                year  = date.Substring(0, 4);
                month = date.Substring(4, 2);
                day   = date.Substring(6, 2);
            }
            catch (Exception)
            {
                //string t = ex.Message;
            }

            XmlUtility.AddChild(valNode.OwnerDocument, valNode, "Year", year);
            XmlUtility.AddChild(valNode.OwnerDocument, valNode, "Month", month);
            XmlUtility.AddChild(valNode.OwnerDocument, valNode, "Day", day);
        }
Exemple #2
0
        private XmlNode GetSelectedAttributesXml(XmlDocument doc, AttributeSet attrSet)
        {
            XmlNode attrSetNode = doc.CreateElement(ATTRIBUTE_SET);

            XmlUtility.AddAttributeNode(doc, attrSetNode, ID, attrSet.attributeSetID.ToString());

            if (attrSet.Attribute != null)
            {
                foreach (Attribute attr in attrSet.Attribute)
                {
                    XmlNode attrNode = XmlUtility.AddChild(doc, attrSetNode, ATTRIBUTE);
                    XmlUtility.AddAttributeNode(doc, attrNode, ID, attr.attributeID.ToString());

                    XmlNode valueElement;
                    Value   val;
                    if (attr.Type == AttributeTypes.ATTR_ID)
                    {
                        CheckSingleValueListItem(attr);
                        val = (Value)attr.Value[0];

                        valueElement = XmlUtility.AddChild(doc, attrNode, VALUE);
                        XmlUtility.AddAttributeNode(doc, valueElement, ID, val.ValueID);

                        if (val.ValueID == (int)ValueIds.OTHER && val.ValueLiteral != null)
                        {
                            // Add one more Attribute node with the same id.
                            XmlNode attrOther = XmlUtility.AddChild(doc, attrSetNode, ATTRIBUTE);
                            XmlUtility.AddAttributeNode(doc, attrOther, ID, attr.attributeID.ToString());

                            XmlNode v_e = XmlUtility.AddChild(doc, attrOther, VALUE);
                            XmlUtility.AddChild(doc, v_e, NAME, val.ValueLiteral);
                        }
                    }
                    else if (attr.Type == AttributeTypes.ATTR_IDS)
                    {
                        foreach (Value v_s in attr.Value)
                        {
                            valueElement = XmlUtility.AddChild(doc, attrNode, VALUE);
                            XmlUtility.AddAttributeNode(doc, valueElement, ID, v_s.ValueID);
                        }
                    }
                    else if (attr.Type == AttributeTypes.ATTR_TEXT)
                    {
                        CheckSingleValueListItem(attr);
                        val = (Value)attr.Value[0];

                        valueElement = XmlUtility.AddChild(doc, attrNode, VALUE);
                        XmlUtility.AddChild(doc, valueElement, NAME, val.ValueLiteral);

                        /*
                         * if( val.ValueId == (int)ValueIds.OTHER )
                         * {
                         *      // Add another attribute node with the same attribute Id
                         *      XmlNode attrOther = XmlUtility.AddChild(doc, attrSetNode, ATTRIBUTE);
                         *      XmlUtility.AddAttributeNode(doc, attrOther, ID, attr.AttributeId.ToString());
                         *
                         *      valueElement = XmlUtility.AddChild(doc, attrOther, VALUE);
                         *      XmlUtility.AddAttributeNode(doc, valueElement, ID, val.ValueId.ToString());
                         * }
                         */
                    }
                    else if (attr.Type == AttributeTypes.ATTR_TEXT_DATE)
                    {
                        CheckSingleValueListItem(attr);
                        val = (Value)attr.Value[0];

                        valueElement = XmlUtility.AddChild(doc, attrNode, VALUE);
                        XmlUtility.AddAttributeNode(doc, valueElement, ID, val.ValueID);

                        AddDateToValueNode(valueElement, val.ValueLiteral);
                    }
                    else
                    {
                        // Unsupported attribute type.
                        foreach (Value v_o in attr.Value)
                        {
                            valueElement = XmlUtility.AddChild(doc, attrNode, VALUE);
                            XmlUtility.AddChild(doc, valueElement, NAME, v_o.ValueLiteral);

                            if (v_o.ValueID != 0)
                            {
                                XmlUtility.AddAttributeNode(doc, valueElement, ID, v_o.ValueID.ToString());
                            }
                        }
                    }
                }
            }

            return(attrSetNode);
        }
Exemple #3
0
        /// <summary>
        /// Extract CS xml by list of CSId from combined CS Xml document.
        /// </summary>
        /// <param name="allCSXml">The CS Xml document that contains multiple CS Xml.</param>
        /// <param name="csIds">List of CSIDs that you want to get Xml for. Set to null to return
        /// xml for all CS.</param>
        /// <param name="copyOverrides">Copy Overrides node or not..</param>
        /// <returns>The new generated Xml document that contains the specified CS Xml.</returns>
        public static XmlDocument ExtractMultiCSFromXml(XmlDocument allCSXml, Int32Collection csIds, bool copyOverrides)
        {
            XmlDocument retXml = null;

            if (csIds == null || csIds.Count == 0)
            {
                retXml = allCSXml;
            }
            else
            {
                XmlNode verNode = allCSXml.SelectSingleNode(SELECT_VERSION);

                //
                retXml = new XmlDocument();
                XmlNode node = retXml.CreateXmlDeclaration("1.0", System.Text.Encoding.Unicode.BodyName, null);
                retXml.AppendChild(node);

                XmlNode eBayNode = XmlUtility.AddChild(retXml, retXml, "eBay");
                retXml.AppendChild(eBayNode);

                XmlNode asNode = XmlUtility.AddChild(retXml, eBayNode, "Attributes");
                XmlNode csNode = XmlUtility.AddChild(retXml, eBayNode, "Characteristics");

                if (verNode != null)
                {
                    eBayNode.AppendChild(retXml.ImportNode(verNode, true));
                }

                XmlNode fromNode;

                foreach (int csId in csIds)
                {
                    // Copy Attributes/AttributeSet
                    fromNode = allCSXml.SelectSingleNode(String.Format(SELECT_AS, csId));
                    if (fromNode == null)
                    {
                        string expMsg = "ExtractMultiCSFromXml: Unable to find source Attributes node the given CSId.\r\n";
                        expMsg += "There is error in the attributes meta-data, please check if the category is \r\n";
                        expMsg += "item specifics enabled(using GetCategoryFeatures) and use eBay item specifics related API instead.\r\n";
                        expMsg += "You may also contact eBay and report the error.";
                        throw new SdkException(expMsg);
                    }
                    asNode.AppendChild(retXml.ImportNode(fromNode, true));

                    // Copy Characteristics/CharacteristicsSet
                    fromNode = allCSXml.SelectSingleNode(String.Format(SELECT_CS, csId));
                    if (fromNode == null)
                    {
                        throw new SdkException("ExtractMultiCSFromXml: Unable to find source Characteristics node the given CSId.");
                    }
                    csNode.AppendChild(retXml.ImportNode(fromNode, true));
                }

                // Copy eBay//API.XSL.Overrides
                if (copyOverrides)
                {
                    fromNode = allCSXml.SelectSingleNode(SELECT_OVERRIDES);
                    if (fromNode != null)
                    {
                        eBayNode.AppendChild(retXml.ImportNode(fromNode, true));
                    }

                    // Copy GlobalSettings
                    fromNode = allCSXml.SelectSingleNode(SELECT_GLOBALSETTINGS);
                    if (fromNode != null)
                    {
                        eBayNode.AppendChild(retXml.ImportNode(fromNode, true));
                    }
                }
            }

            return(retXml);
        }