Esempio n. 1
0
        // This method validates xsi:type="dcterms:W3CDTF"
        // The valude of xsi:type is a qualified name. It should have a prefix that matches
        //  the xml namespace (ns) within the scope and the name that matches name
        // The comparisons should be case-sensitive comparisons
        internal static void ValidateXsiType(XmlTextReader reader, Object ns, string name)
        {
            // Get the value of xsi;type
            String typeValue = reader.GetAttribute(PackageXmlStringTable.GetXmlString(PackageXmlEnum.Type),
                                                   PackageXmlStringTable.GetXmlString(PackageXmlEnum.XmlSchemaInstanceNamespace));

            // Missing xsi:type
            if (typeValue == null)
            {
                throw new XmlException(SR.Get(SRID.UnknownDCDateTimeXsiType, reader.Name),
                                       null, reader.LineNumber, reader.LinePosition);
            }

            int index = typeValue.IndexOf(':');

            // The valude of xsi:type is not a qualified name
            if (index == -1)
            {
                throw new XmlException(SR.Get(SRID.UnknownDCDateTimeXsiType, reader.Name),
                                       null, reader.LineNumber, reader.LinePosition);
            }

            // Check the following conditions
            //  The namespace of the prefix (string before ":") matches "ns"
            //  The name (string after ":") matches "name"
            if (!Object.ReferenceEquals(ns, reader.LookupNamespace(typeValue.Substring(0, index))) ||
                String.CompareOrdinal(name, typeValue.Substring(index + 1, typeValue.Length - index - 1)) != 0)
            {
                throw new XmlException(SR.Get(SRID.UnknownDCDateTimeXsiType, reader.Name),
                                       null, reader.LineNumber, reader.LinePosition);
            }
        }
        /// <summary>
        /// Gets URI of the QName
        /// </summary>
        /// <param name="xmlReader">the XmlTextReader object</param>
        /// <param name="QName">the qualified name</param>
        /// <returns>URI of the QName (null if no matching namespace is found)</returns>
        /// <exception>none</exception>
        public static string GetURI(XmlTextReader xmlReader, string QName)
        {
            int colonIndex = QName.IndexOf(":", StringComparison.Ordinal);

            string prefix = (colonIndex == (-1)) ? "" : QName.Substring(0, colonIndex);

            // Prefix is non-null (could be empty), so LookupNamespace won't throw exception.
            // It will return null if no matching prefix is found.
            return(xmlReader.LookupNamespace(prefix));
        }
        private static DocumentInfo GetDocumentInfo(string filePath)
        {
            try
            {
                using (var reader = new XmlTextReader(filePath))
                {
                    while (reader.Read())
                    {
                        // get first element
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            var name = reader.LocalName;
                            var ns   = reader.LookupNamespace(reader.Prefix);

                            var attributes     = new List <KeyValuePair <string, string> >();
                            var attributeCount = reader.AttributeCount;
                            for (var i = 0; i < attributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                var attributeName  = reader.LocalName;
                                var attributeValue = reader.GetAttribute(i);
                                attributes.Add(new KeyValuePair <string, string>(attributeName, attributeValue));
                            }

                            return(new DocumentInfo
                            {
                                RootElement = name,
                                Namespace = ns,
                                Attributes = attributes,
                            });
                        }
                    }
                }
            }
            catch (XmlException ex)
            {
                // root element not contained, so ignore
                Tracer.Trace($"While parsing '{filePath}', following {ex.GetType().Name} was thrown: {ex}", ex);
            }

            return(null);
        }
Esempio n. 4
0
        private object DeserializeArray(long id)
        {
            // Special case for base64 byte arrays
            if (GetComponentType() == typeof(byte[]))
            {
                byte[] data = Convert.FromBase64String(xmlReader.ReadElementString());
                RegisterObject(id, data, null, 0, null, null);
                return(data);
            }

            // Get the array properties
            string strArrayType = xmlReader["arrayType", SoapTypeMapper.SoapEncodingNamespace];

            string[] arrayInfo        = strArrayType.Split(':');
            int      arraySuffixInfo  = arrayInfo[1].LastIndexOf('[');
            String   arrayElementType = arrayInfo[1].Substring(0, arraySuffixInfo);
            String   arraySuffix      = arrayInfo[1].Substring(arraySuffixInfo);

            string[] arrayDims    = arraySuffix.Substring(1, arraySuffix.Length - 2).Trim().Split(',');
            int      numberOfDims = arrayDims.Length;

            int[] lengths = new int[numberOfDims];

            for (int i = 0; i < numberOfDims; i++)
            {
                lengths[i] = Convert.ToInt32(arrayDims[i]);
            }

            int[] indices = new int[numberOfDims];

            // Create the array
            Type  arrayType = mapper.GetType(arrayElementType, xmlReader.LookupNamespace(arrayInfo[0]));
            Array array     = Array.CreateInstance(
                arrayType,
                lengths);

            for (int i = 0; i < numberOfDims; i++)
            {
                indices[i] = array.GetLowerBound(i);
            }

            // Deserialize the array items
            int arrayDepth = xmlReader.Depth;

            xmlReader.Read();
            while (xmlReader.Depth > arrayDepth)
            {
                Type itemType = GetComponentType();
                if (itemType == null)
                {
                    itemType = array.GetType().GetElementType();
                }
                long itemId, itemHref;

                object objItem = DeserializeComponent(itemType,
                                                      out itemId,
                                                      out itemHref,
                                                      id,
                                                      null,
                                                      indices);
                if (itemHref != 0)
                {
                    object obj = objMgr.GetObject(itemHref);
                    if (obj != null)
                    {
                        array.SetValue(obj, indices);
                    }
                    else
                    {
                        RecordFixup(id, itemHref, array, null, null, null, indices);
                    }
                }
                else if (objItem != null && objItem.GetType().IsValueType&& itemId != 0)
                {
                    RecordFixup(id, itemId, array, null, null, null, indices);
                }
                else if (itemId != 0)
                {
                    RegisterObject(itemId, objItem, null, id, null, indices);
                    array.SetValue(objItem, indices);
                }
                else
                {
                    array.SetValue(objItem, indices);
                }

                // Get the next indice
                for (int dim = array.Rank - 1; dim >= 0; dim--)
                {
                    indices[dim]++;
                    if (indices[dim] > array.GetUpperBound(dim))
                    {
                        if (dim > 0)
                        {
                            indices[dim] = array.GetLowerBound(dim);
                            continue;
                        }
                    }
                    break;
                }
            }

            RegisterObject(id, array, null, 0, null, null);
            xmlReader.ReadEndElement();
            return(array);
        }
Esempio n. 5
0
        //
        // TODO: see if there is a way to better modularize this method and rename it.
        //
        private void CheckForSingleRequest(Stream stream)
        {
            try
            {
                //
                // Move to the start of our stream
                //
                stream.Position = 0;
                XmlTextReader requestReader = new XmlTextReader(oldStream);
                requestReader.MoveToContent();

                //
                // TODO: should not hard-code SOAP names and namespaces
                //

                //
                // Move to the beginning of the SOAP envelope
                //
                requestReader.ReadStartElement("Envelope", "http://schemas.xmlsoap.org/soap/envelope/");

                //
                // Move to the SOAP body
                //
                while (!requestReader.IsStartElement("Body", "http://schemas.xmlsoap.org/soap/envelope/") && !requestReader.EOF)
                {
                    requestReader.Skip();
                }

                //
                // Advance the current node to the first child of Body.  This is presumably the UDDI message
                //
                requestReader.ReadStartElement("Body", "http://schemas.xmlsoap.org/soap/envelope/");
                requestReader.MoveToContent();

                //
                // This element MUST have a UDDI namespace
                //
                string uddiNamespace = requestReader.LookupNamespace(requestReader.Prefix);

                switch (uddiNamespace)
                {
                case "urn:uddi-org:api":
                {
                    Context.ApiVersionMajor = 1;
                    break;
                }

                case "urn:uddi-org:api_v2":
                {
                    Context.ApiVersionMajor = 2;
                    break;
                }

                case "urn:uddi-microsoft-com:api_v2_extensions":
                {
                    Context.ApiVersionMajor = 2;
                    break;
                }

                case "urn:uddi-org:repl":
                {
                    Context.ApiVersionMajor = 2;
                    break;
                }

                default:
                {
                    //
                    // This is a problem, we don't have a UDDI namespace.  Throw an exception and get out of here.  The
                    // exception will be caught in our outer catch and sent to our client using DispositionReport.ThrowFinal.
                    //

                    throw new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_MISSINGUDDINS");
                }
                }

                //
                // Skip the children of this node
                //
                requestReader.Skip();
                requestReader.MoveToContent();

                //
                // Reset our stream so someone else can use it.
                //
                stream.Position = 0;

                //
                // If we are not at the end of the Body tag, then we have multiple requests, we should reject the message.
                //
                if (false == requestReader.LocalName.Equals("Body"))
                {
                    DispositionReport.ThrowFinal(new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_SOAP_MULTIPLEREQUEST"));
                }
            }
            catch (UDDIException uddiException)
            {
                DispositionReport.ThrowFinal(uddiException);
            }
            catch
            {
                //
                // We'll get this exception if the message contains any invalid elements
                //
                DispositionReport.ThrowFinal(new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_SOAP_INVALIDELEMENT"));
            }
        }
Esempio n. 6
0
        private static UPnPComplexType ParseComplexType(XmlTextReader X, UPnPComplexType RetVal)
        {
            string elementName = X.LocalName;
            int    count       = 0;
            bool   done        = false;
            DText  P           = new DText();

            P.ATTRMARK = ":";

            RetVal.AddContainer(new GenericContainer());

            do
            {
                switch (X.NodeType)
                {
                case XmlNodeType.Element:
                    switch (X.LocalName)
                    {
                    case "complexType":
                    case "group":
                        ++count;
                        if (X.HasAttributes)
                        {
                            for (int i = 0; i < X.AttributeCount; i++)
                            {
                                X.MoveToAttribute(i);
                                if (X.Name == "name")
                                {
                                    P[0] = X.Value;
                                    if (P.DCOUNT() == 1)
                                    {
                                        RetVal.LocalName = X.Value;
                                        RetVal.NameSpace = X.LookupNamespace("");
                                    }
                                    else
                                    {
                                        RetVal.LocalName = P[2];
                                        RetVal.NameSpace = X.LookupNamespace(P[1]);
                                    }
                                }
                                else if (X.Name == "ref")
                                {
                                    // NOP
                                }
                            }
                            X.MoveToElement();
                        }
                        break;

                    case "sequence":
                    case "choice":
                        RetVal.CurrentContainer.AddCollection(ParseComplexType_SequenceChoice(X));
                        //ParseComplexType_Sequence(X,RetVal);
                        break;

                    case "complexContent":
                        RetVal.AddContainer(new ComplexContent());
                        break;

                    case "simpleContent":
                        RetVal.AddContainer(new SimpleContent());
                        break;

                    case "restriction":
                        Restriction r = new Restriction();
                        if (RetVal.CurrentContainer.GetType() == typeof(ComplexContent))
                        {
                            ((ComplexContent)RetVal.CurrentContainer).RestExt = r;
                        }
                        else if (RetVal.CurrentContainer.GetType() == typeof(SimpleContent))
                        {
                            ((SimpleContent)RetVal.CurrentContainer).RestExt = r;
                        }
                        if (X.HasAttributes)
                        {
                            for (int i = 0; i < X.AttributeCount; i++)
                            {
                                X.MoveToAttribute(i);
                                if (X.Name == "base")
                                {
                                    P[0] = X.Value;
                                    if (P.DCOUNT() == 1)
                                    {
                                        r.baseType   = X.Value;
                                        r.baseTypeNS = X.LookupNamespace("");
                                    }
                                    else
                                    {
                                        r.baseType   = P[2];
                                        r.baseTypeNS = X.LookupNamespace(P[1]);
                                    }
                                }
                            }
                            X.MoveToElement();
                        }
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (X.LocalName == elementName)
                    {
                        --count;
                        if (count == 0)
                        {
                            done = true;
                        }
                    }
                    break;

                case XmlNodeType.Text:
                    break;
                }
            }while(!done && X.Read());
            return(RetVal);
        }
Esempio n. 7
0
        private static ItemCollection ParseComplexType_SequenceChoice(XmlTextReader X)
        {
            bool           done = false;
            ItemCollection RetVal;
            string         elementName = X.LocalName;
            DText          p           = new DText();

            p.ATTRMARK = ":";

            if (X.LocalName == "choice")
            {
                RetVal = new Choice();
            }
            else
            {
                RetVal = new Sequence();
            }

            if (X.HasAttributes)
            {
                for (int i = 0; i < X.AttributeCount; i++)
                {
                    X.MoveToAttribute(i);
                    switch (X.LocalName)
                    {
                    case "minOccurs":
                        RetVal.MinOccurs = X.Value;
                        break;

                    case "maxOccurs":
                        RetVal.MaxOccurs = X.Value;
                        break;
                    }
                }
                X.MoveToElement();
            }
            X.Read();


            do
            {
                switch (X.NodeType)
                {
                case XmlNodeType.Element:
                    switch (X.LocalName)
                    {
                    case "group":
                        if (X.HasAttributes)
                        {
                            for (int i = 0; i < X.AttributeCount; i++)
                            {
                                X.MoveToAttribute(i);
                                switch (X.LocalName)
                                {
                                case "ref":
                                    break;
                                }
                            }
                            X.MoveToElement();
                        }
                        break;

                    case "sequence":
                    case "choice":
                        RetVal.AddCollection(ParseComplexType_SequenceChoice(X));
                        break;

                    case "element":
                        RetVal.AddContentItem(new Element());
                        if (X.HasAttributes)
                        {
                            for (int i = 0; i < X.AttributeCount; i++)
                            {
                                X.MoveToAttribute(i);
                                switch (X.LocalName)
                                {
                                case "name":
                                    RetVal.CurrentItem.Name = X.Value;
                                    break;

                                case "type":
                                    p[0] = X.Value;
                                    if (p.DCOUNT() == 1)
                                    {
                                        RetVal.CurrentItem.Type   = X.Value;
                                        RetVal.CurrentItem.TypeNS = X.LookupNamespace("");
                                    }
                                    else
                                    {
                                        RetVal.CurrentItem.Type   = p[2];
                                        RetVal.CurrentItem.TypeNS = X.LookupNamespace(p[1]);
                                    }
                                    break;

                                case "minOccurs":
                                    RetVal.CurrentItem.MinOccurs = X.Value;
                                    break;

                                case "maxOccurs":
                                    RetVal.CurrentItem.MaxOccurs = X.Value;
                                    break;
                                }
                            }
                            X.MoveToElement();
                        }
                        break;

                    case "attribute":
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (X.LocalName == elementName)
                    {
                        done = true;
                    }
                    break;

                case XmlNodeType.Text:
                    break;
                }
            }while(!done && X.Read());

            return(RetVal);
        }
        /// <summary>
        /// Reads the data type from an XML stream.
        /// </summary>
        private System.Type ReadType(XmlTextReader reader, string type)
        {
            bool   array         = false;
            string parsedType    = type;
            string typeNamespace = null;

            // extract namespace.
            int index = parsedType.IndexOf(":");

            if (index != -1)
            {
                typeNamespace = reader.LookupNamespace(parsedType.Substring(0, index));
                parsedType    = parsedType.Substring(index + 1);
            }

            // remove array prefix.
            if (type.StartsWith(ARRAY_OF))
            {
                parsedType = type.Substring(ARRAY_OF.Length, 1).ToLower() + type.Substring(ARRAY_OF.Length + 1);
                array      = true;
            }

            // check for standard types.
            if (parsedType == "byte")
            {
                return((array)?typeof(sbyte[]):typeof(sbyte));
            }
            if (parsedType == "unsignedByte")
            {
                return((array)?typeof(byte[]):typeof(byte));
            }
            if (parsedType == "short")
            {
                return((array)?typeof(short[]):typeof(short));
            }
            if (parsedType == "unsignedShort")
            {
                return((array)?typeof(ushort[]):typeof(ushort));
            }
            if (parsedType == "int")
            {
                return((array)?typeof(int[]):typeof(int));
            }
            if (parsedType == "unsignedInt")
            {
                return((array)?typeof(uint[]):typeof(uint));
            }
            if (parsedType == "long")
            {
                return((array)?typeof(long[]):typeof(long));
            }
            if (parsedType == "unsignedLong")
            {
                return((array)?typeof(ulong[]):typeof(ulong));
            }
            if (parsedType == "float")
            {
                return((array)?typeof(float[]):typeof(float));
            }
            if (parsedType == "double")
            {
                return((array)?typeof(double[]):typeof(double));
            }
            if (parsedType == "decimal")
            {
                return((array)?typeof(decimal[]):typeof(decimal));
            }
            if (parsedType == "string")
            {
                return((array)?typeof(string[]):typeof(string));
            }
            if (parsedType == "boolean")
            {
                return((array)?typeof(bool[]):typeof(bool));
            }
            if (parsedType == "dateTime")
            {
                return((array)?typeof(DateTime[]):typeof(DateTime));
            }
            if (parsedType == "anyType")
            {
                return((array)?typeof(object[]):typeof(object));
            }
            if (parsedType == "hexBinary")
            {
                return((array)?typeof(string[]):typeof(string));
            }

            // unsupported xml schema defined data type.
            if (typeNamespace == Opc.Namespace.XML_SCHEMA)
            {
                return(null);
            }

            // must be complex type.
            return(typeof(object[]));
        }
Esempio n. 9
0
        private static ItemCollection ParseComplexType_SequenceChoice(XmlTextReader X)
        {
            bool           flag      = false;
            ItemCollection items     = null;
            string         localName = X.LocalName;
            DText          text      = new DText();

            text.ATTRMARK = ":";
            if (X.LocalName == "choice")
            {
                items = new Choice();
            }
            else
            {
                items = new Sequence();
            }
            if (X.HasAttributes)
            {
                for (int i = 0; i < X.AttributeCount; i++)
                {
                    X.MoveToAttribute(i);
                    switch (X.LocalName)
                    {
                    case "minOccurs":
                        items.MinOccurs = X.Value;
                        break;

                    case "maxOccurs":
                        items.MaxOccurs = X.Value;
                        break;
                    }
                }
                X.MoveToElement();
            }
            X.Read();
            do
            {
                switch (X.NodeType)
                {
                case XmlNodeType.Element:
                {
                    string str = X.LocalName;
                    if (str != null)
                    {
                        str = string.IsInterned(str);
                        if (str == "group")
                        {
                            if (X.HasAttributes)
                            {
                                for (int j = 0; j < X.AttributeCount; j++)
                                {
                                    string str5;
                                    X.MoveToAttribute(j);
                                    if (((str5 = X.LocalName) != null) && (string.IsInterned(str5) == "ref"))
                                    {
                                        string str2 = X.Value;
                                    }
                                }
                                X.MoveToElement();
                            }
                        }
                        else
                        {
                            if ((str == "sequence") || (str == "choice"))
                            {
                                items.AddCollection(ParseComplexType_SequenceChoice(X));
                                break;
                            }
                            if (str == "element")
                            {
                                items.AddContentItem(new Element());
                                if (X.HasAttributes)
                                {
                                    for (int k = 0; k < X.AttributeCount; k++)
                                    {
                                        X.MoveToAttribute(k);
                                        switch (X.LocalName)
                                        {
                                        case "name":
                                            items.CurrentItem.Name = X.Value;
                                            break;

                                        case "type":
                                            text[0] = X.Value;
                                            if (text.DCOUNT() == 1)
                                            {
                                                items.CurrentItem.Type   = X.Value;
                                                items.CurrentItem.TypeNS = X.LookupNamespace("");
                                            }
                                            else
                                            {
                                                items.CurrentItem.Type   = text[2];
                                                items.CurrentItem.TypeNS = X.LookupNamespace(text[1]);
                                            }
                                            break;

                                        case "minOccurs":
                                            items.CurrentItem.MinOccurs = X.Value;
                                            break;

                                        case "maxOccurs":
                                            items.CurrentItem.MaxOccurs = X.Value;
                                            break;
                                        }
                                    }
                                    X.MoveToElement();
                                }
                                break;
                            }
                            if (str == "attribute")
                            {
                            }
                        }
                    }
                    break;
                }

                case XmlNodeType.EndElement:
                    if (X.LocalName == localName)
                    {
                        flag = true;
                    }
                    break;
                }
            }while (!flag && X.Read());
            return(items);
        }
Esempio n. 10
0
        private static UPnPComplexType ParseComplexType(XmlTextReader X, UPnPComplexType RetVal)
        {
            string localName = X.LocalName;
            int    num       = 0;
            bool   flag      = false;
            DText  text      = new DText();

            text.ATTRMARK = ":";
            RetVal.AddContainer(new GenericContainer());
            do
            {
                switch (X.NodeType)
                {
                case XmlNodeType.Element:
                {
                    string str = X.LocalName;
                    if (str != null)
                    {
                        str = string.IsInterned(str);
                        if ((str == "complexType") || (str == "group"))
                        {
                            num++;
                            if (X.HasAttributes)
                            {
                                for (int i = 0; i < X.AttributeCount; i++)
                                {
                                    X.MoveToAttribute(i);
                                    if (X.Name == "name")
                                    {
                                        text[0] = X.Value;
                                        if (text.DCOUNT() == 1)
                                        {
                                            RetVal.LocalName = X.Value;
                                            RetVal.NameSpace = X.LookupNamespace("");
                                        }
                                        else
                                        {
                                            RetVal.LocalName = text[2];
                                            RetVal.NameSpace = X.LookupNamespace(text[1]);
                                        }
                                    }
                                    else if (X.Name == "ref")
                                    {
                                    }
                                }
                                X.MoveToElement();
                            }
                        }
                        else
                        {
                            if ((str == "sequence") || (str == "choice"))
                            {
                                RetVal.CurrentContainer.AddCollection(ParseComplexType_SequenceChoice(X));
                                break;
                            }
                            if (str == "complexContent")
                            {
                                RetVal.AddContainer(new ComplexContent());
                                break;
                            }
                            if (str == "simpleContent")
                            {
                                RetVal.AddContainer(new SimpleContent());
                                break;
                            }
                            if (str == "restriction")
                            {
                                Restriction restriction = new Restriction();
                                if (RetVal.CurrentContainer.GetType() == typeof(ComplexContent))
                                {
                                    ((ComplexContent)RetVal.CurrentContainer).RestExt = restriction;
                                }
                                else if (RetVal.CurrentContainer.GetType() == typeof(SimpleContent))
                                {
                                    ((SimpleContent)RetVal.CurrentContainer).RestExt = restriction;
                                }
                                if (X.HasAttributes)
                                {
                                    for (int j = 0; j < X.AttributeCount; j++)
                                    {
                                        X.MoveToAttribute(j);
                                        if (X.Name == "base")
                                        {
                                            text[0] = X.Value;
                                            if (text.DCOUNT() == 1)
                                            {
                                                restriction.baseType   = X.Value;
                                                restriction.baseTypeNS = X.LookupNamespace("");
                                            }
                                            else
                                            {
                                                restriction.baseType   = text[2];
                                                restriction.baseTypeNS = X.LookupNamespace(text[1]);
                                            }
                                        }
                                    }
                                    X.MoveToElement();
                                }
                                break;
                            }
                        }
                    }
                    break;
                }

                case XmlNodeType.EndElement:
                    if (X.LocalName == localName)
                    {
                        num--;
                        if (num == 0)
                        {
                            flag = true;
                        }
                    }
                    break;
                }
            }while (!flag && X.Read());
            return(RetVal);
        }