开发者

"Could not find schema information for the element" - but my schema file does contain information for the element

开发者 https://www.devze.com 2023-03-26 04:53 出处:网络
I\'m trying to work with an application that i don\'t have the source code for.I\'m trying to interface in some data in an XML file.i believe my file matches the applications required schema correctly

I'm trying to work with an application that i don't have the source code for. I'm trying to interface in some data in an XML file. i believe my file matches the applications required schema correctly, but i get the message "Could not find schema information for the element" for every element in my file. I've decomplied the applications code and rebuilt it in visual studio, and i get the error myself.

I'm going to go ahead and just dump the code... Its pretty long, but i'm starting to think its a pretty bone head mistake on my part.

The XML to be imported:

<WorkOrders>
    <WorkOrder>
        <Action>SAVE</Action>
        <UserDef1>NotRequired1</UserDef1>
        <UserDef2>NotRequired2</UserDef2>
        <UserDef3>NotRequired3</UserDef3>
        <UserDef4>NotRequired4</UserDef4>
        <UserDef5>NotRequired5</UserDef5>
        <UserDef6>NotRequired6</UserDef6>
        <UserDef7>-1</UserDef7>
        <UserDef8>-2</UserDef8>
        <AutoRelease>N</AutoRelease> <!--Probably can hardcode as N-->
        <BuildInstructions>Not Required BuildInstructions</BuildInstructions>
        <!--<BuildLocation>Not required BuildLocation</BuildLocation>-->
        <Company></Company> <!--should match compan on the item master-->
        <!--<DimensionUm></DimensionUm>-->
        <DueDate>12-31-2011</DueDate>
        <!--<Error></Error>-->
        <FinishedItem>SERIAL_TEST</FinishedItem>
        <QtyToBeBuilt>12345</QtyToBeBuilt>
        <!--<QtyUm></QtyUm>
        <RevisionNum></RevisionNum>-->
        <Warehouse>PPLant</Warehouse>
        <WeightUm></WeightUm>
        <WOAllocMethod></WOAllocMethod>
        <WorkOrderDetails>
            <Action>SAVE</Action>
            <UserDef1>NotRequired1</UserDef1>
            <UserDef2>NotRequired2</UserDef2>
            <UserDef3>NotRequired3</UserDef3>
            <UserDef4>NotRequired4</UserDef4>
            <UserDef5>NotRequired5</UserDef5>
            <UserDef6>NotRequired6</UserDef6>
            <UserDef7>-1</UserDef7>
            <UserDef8>-2</UserDef8>
            <AllocationRule>WorkOrderAllocation</AllocationRule>
            <BuildLevel>1</BuildLevel>
            <!--<BuildSequence>1</BuildSequence>-->
            <Company></Company>
            <ComponentItem>SERIAL_TEST</ComponentItem>
            <FromLocation></FromLocation>-->
            <!-- these fields allow users to increase/decrease the component quantity required
            <IncQtyAmount></IncQtyAmount>
            <IncQtyEligible></IncQtyEligible>
            <IncQtyMinAmount></IncQtyMinAmount>
            <IncQtyType></IncQtyType>-->
            <!-- <LogisticsUnit></LogisticsUnit>
            <Lot></Lot>
            <ParentLogisticsUnit></ParentLogisticsUnit>-->
            <QtyNeededPerItem>10</QtyNeededPerItem>
            <!--<QuantityUm></QuantityUm>-->
            <Warehouse>PPLant</Warehouse>
        </WorkOrderDetails>
        <WorkOrderId>ExampleWorkOrderID001</WorkOrderId>
        <AllocationRule>WorkOrderAllocation</AllocationRule>

    </WorkOrder>
</WorkOrders>

The schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="WorkOrderDownload" targetNamespace="http://www.asdf.com/asdfNET/Interface" elementFormDefault="qualified" xmlns="http://www.asdf.com/asdfNET/Interface" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2008">
    <xs:include schemaLocation="InterfaceEntity.xsd" />
    <xs:element name="WorkOrders" nillable="false" type="WorkOrderList" />
    <xs:complexType name="WorkOrderList">
        <xs:sequence>
            <xs:element minOccurs="1" maxOccurs="unbounded" name="WorkOrder" nillable="true" type="WorkOrder" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="WorkOrder">
        <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="1" name="AutoRelease" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="BuildInstructions" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="BuildLocation" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="Company" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="DimensionUm" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="DueDate" type="xs:dateTime" />
            <xs:element minOccurs="0" maxOccurs="1" name="Error" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="FinishedItem" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="InterfaceEntity" type="InterfaceEntity" />
            <xs:element minOccurs="0" maxOccurs="1" name="InternalWorkOrderNum" type="xs:int" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemClass" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemColor" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemCost">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="ItemDescription" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemHeight">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="ItemLength">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="ItemSize" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemStyle" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemValue">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="ItemWeight">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="ItemWidth">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="PlannedUnitBuildTime">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="QtyToBeBuilt">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="1" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="QtyUm" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="RevisionNum">
                <xs:simpleType>
                    <xs:restriction base="xs:int">
                        <xs:minInclusive value="1" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="VolumeUm" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="Warehouse" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="WeightUm" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="WOAllocMethod" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="WorkOrderDetails" type="WorkOrderDetailList" />
            <xs:element minOccurs="0" maxOccurs="1" name="WorkOrderId" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="WorkOrderDetailList">
        <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="unbounded" name="WorkOrderDetail" nillable="true" type="WorkOrderDetail" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="WorkOrderDetail">
        <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="1" name="AllocationRule" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="BuildLevel">
                <xs:simpleType>
                    <xs:restriction base="xs:int">
                        <xs:minInclusive value="1" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="BuildSequence">
                <xs:simpleType>
                    <xs:restriction base="xs:int">
                        <xs:minInclusive value="1" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="Company" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ComponentItem" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="FromLocation" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="IncQtyAmount" type="xs:double" />
            <xs:element minOccurs="0" maxOccurs="1" name="IncQtyEligible" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="IncQtyMinAmount">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="IncQtyType" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="InterfaceEntity" type="InterfaceEntity" />
            <xs:element minOccurs="0" maxOccurs="1" name="InternalWorkOrderNum">
                <xs:simpleType>
                    <xs:restriction base="xs:int">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="LogisticsUnit" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="Lot" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ParentLogisticsUnit" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="QtyNeededPerItem">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="1" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="QuantityUm" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="Warehouse" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
</xs:schema>

the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;

namespace WorkOrderInterfaceValidation
{
    class Program
    {
        static void Main(string[] args)
        {
            helper h = new helper();
            h.main();
        }
    }

    class helper
    {
        StringBuilder _valErrorMsgs;

        public helper()
        {
            _valErrorMsgs = new StringBuilder();
        }

        public void main()
        {
            try
            {
                string error = "No error";
                Console.WriteLine("hello world");

                ValidateSchemaWithURI("C:\\Program Files\\software\\asdf\\2010\\Interface\\Input\\ExampleWorkOrder001.xml",
                    "http://www.asdf.com/asdfNET/Interface",
                    "\\\\localhost\\asdf\\Schemas\\Interface\\WorkOrderDownload.xsd",
                    out error
                    );

                error += " err";
                Console.WriteLine(error);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadKey();
        }

        public XmlReader ValidateSchemaWithURI(string inputUri, string targetNamespace, string schemaPath, out string error)
        {
            //StringBuilder _valErrorMsgs = new StringBuilder();
            XmlReader reader = null;
            XmlReader reader2;
            try
            {
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.Schemas.Add(targetNamespace, schemaPath);
                settings.IgnoreWhitespace = true;
                settings.ValidationType = ValidationType.Schema;
                settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
                settings.ValidationEventHandler += new ValidationEventHandler(this.SchemaValidationEventHandler);
                reader = XmlReader.Create(inputUri, settings);

                foreach (var v in settings.Schemas.Schemas())
                {
                    foreach (var e in ((XmlSchema)v).Attributes)
                    {
                        e.ToString();
                    }
                }

                while (reader.Read())
               开发者_JS百科 {

                }
                reader2 = reader;
            }
            catch (XmlException exception)
            {
                _valErrorMsgs.Append(exception.Message).Append(";");
                Console.WriteLine(exception.Message);
                reader2 = null;
            }
            finally
            {
                error = _valErrorMsgs.ToString();
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return reader2;
        }

        private void SchemaValidationEventHandler(object sender, ValidationEventArgs args)
        {
            this._valErrorMsgs.Append(args.Exception.Message).Append(";");
        }
    }
}

The error message:

XmlException: Could not find schema information for the element 'WorkOrders'.;Could not find schema information for the element 'WorkOrder'.;Could not find schema information for the element 'Action'.;Could not find schema information for the element 'UserDef1'.;Could not find schema information for the element 'UserDef2'.;Could not find schema information for the element 'UserDef3'.;Could not find schema information for the element 'UserDef4'.;Could not find schema information for the ....


I think you're missing the namespace. Try:

<WorkOrders xmlns="http://www.manh.com/ILSNET/Interface">
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号