[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] still import problem
I still couldn't find the mistake I have made.:( For debug and watch convenience, I add the vb script here(Main.vbs) and the xml instance(Main.xml).all these file need to put into the same folder, and windows OS and MS XML SDK 4.0 required. '/////////////////////////////////////////////////////////////////// Main.vbs ' Item types: SOMITEM_SCHEMA = 4*1024 SOMITEM_ATTRIBUTE = SOMITEM_SCHEMA + 1 SOMITEM_ATTRIBUTEGROUP = SOMITEM_SCHEMA + 2 SOMITEM_NOTATION = SOMITEM_SCHEMA + 3 SOMITEM_ANYTYPE = 8*1024 SOMITEM_DATATYPE = SOMITEM_ANYTYPE+256 SOMITEM_SIMPLETYPE = SOMITEM_DATATYPE+256 SOMITEM_COMPLEXTYPE = 9*1024 SOMITEM_PARTICLE = 16*1024 SOMITEM_ANY = SOMITEM_PARTICLE+1 SOMITEM_ANYATTRIBUTE = SOMITEM_PARTICLE+2 SOMITEM_ELEMENT = SOMITEM_PARTICLE+3 SOMITEM_GROUP = SOMITEM_PARTICLE+256 SOMITEM_ALL = SOMITEM_GROUP+1 SOMITEM_CHOICE = SOMITEM_GROUP+2 SOMITEM_SEQUENCE = SOMITEM_GROUP+3 SOMITEM_EMPTYPARTICLE = SOMITEM_GROUP+4 SCHEMAUSE_OPTIONAL = 0 SCHEMAUSE_PROHIBITED = 1 SCHEMAUSE_REQUIRED = 2 SCHEMACONTENTTYPE_EMPTY = 0 SCHEMACONTENTTYPE_TEXTONLY = 1 SCHEMACONTENTTYPE_ELEMENTONLY = 2 SCHEMACONTENTTYPE_MIXED = 3 remarks = 0 Set oSchemaCache = CreateObject("Msxml2.XMLSchemaCache.4.0") nsTarget="http://www.test.com/ok" oSchemaCache.add nsTarget, "main_derive.xsd" Set oDoc = CreateObject("Msxml2.DOMDocument.4.0") oDoc.async = false oDoc.validateOnParse = false set oDoc.schemas = oSchemaCache if oDoc.load( "main.xml") = false then WScript.Echo "load xml document failed" end if oDoc.setProperty "SelectionLanguage", "XPath" oDoc.setProperty "SelectionNamespaces", "xmlns:MN='http://www.test.com/ok' xmlns:XSI='http://www.w3.org/2001/XMLSchema-instance'" result = "" 'Set oNo = oDoc.selectSingleNode("//cust:*[@curCursorIn]") 'Set oNo = oDoc.selectSingleNode("//cust:Customers/zz/Ö¢×´Ãû³Æ") Set oNo = oDoc.selectSingleNode("//MN:*[@curCursorIn]") 'Set oNo = oDoc.selectSingleNode("//MN:ECase/Ö÷Ëß/Ö¢×´ÃèÊö") 'Set oNo = oDoc.selectSingleNode("//MN:Ö¢×´ÃèÊö") if oNo is Nothing then WScript.Echo "no node selected" end if result = result + printDecl(oNo) + vbNewLine 'Set oNo = oDoc.selectSingleNode("//po:purchaseOrder/items/item/quantity") 'result = result + printDecl(oNo) + vbNewLine 'Set oNo = oDoc.selectSingleNode("//po:purchaseOrder/items") 'result = result + printDecl(oNo) + vbNewLine 'Set oNo = oDoc.selectSingleNode("//po:purchaseOrder/items/item/@partNum") 'result = result + printDecl(oNo) + vbNewLine 'Set oNo = oDoc.selectSingleNode("//po:purchaseOrder/shipTo") 'result = result + printDecl(oNo) + vbNewLine WScript.Echo result Function printDecl(oNode) If oNode is nothing then exit function Set oDecl = oDoc.namespaces.getDeclaration(oNode) If oDecl.itemType = SOMITEM_ELEMENT Then printDecl = printElement(oDecl, 1) End If If oDecl.itemType = SOMITEM_ATTRIBUTE Then printDecl = printAttr(oDecl, 1) printDecl = printDecl + processType(oDecl.Type, 1) End If End Function Function processType(oType, t) If oType.itemType = SOMITEM_ANYTYPE Then res = res + printTab(t+1) + "<!-- " + oType.name +" -->" End If If oType.itemType = SOMITEM_COMPLEXTYPE Then res = res + processComplexType(oType, t+1) End If If oType.itemType = SOMITEM_SIMPLETYPE Then res = res + processSimpleType(oType, t+1) End If processType = res + vbNewLine End Function Function processComplexType(oComplex, t) res = printTab(t) + "<xsd:complexType" If oComplex.name <> "" Then res = res + " name='" + oComplex.name +"'" End If res = res + ">" If oComplex.contentType = SCHEMACONTENTTYPE_EMPTY Then res = res + printRemark("emtpy") End If If oComplex.contentType = SCHEMACONTENTTYPE_TEXTONLY Then res = res + printRemark("textonly") End If If oComplex.contentType =SCHEMACONTENTTYPE_ELEMENTONLY Then res = res + printRemark("elementonly") res = res + processGroup(oComplex.contentModel, t+1) End If If oComplex.contentType = SCHEMACONTENTTYPE_MIXED Then res = res + printRemark("mixed") res = res + processGroup(oComplex.contentModel, t+1) End If res = res + vbNewline res = res + printRestrictions(oComplex, t+1) On Error Resume Next Set any = oComplex.anyAttribute.name If Err.number = 0 Then res = res + oComplex.anyAttribute.name End If For Each oAttr in oComplex.attributes res = res + printAttr(oAttr, t+1) Next processComplexType = res + printTab(t) + "</xsd:complexType>"+vbNewline End Function Function processSimpleType(oSimple, t) res = printTab(t) + "<xsd:simpleType" If oSimple.name <> "" Then res = res + " name='" + oSimple.name +"'" End If res = res + ">"+vbNewline If oSimple.baseTypes.length = 1 Then res = res + printRestrictions(oSimple, t+1) Else For Each oType in oSimple.baseTypes res = res + "<baseType name='" + printName(oType) +"'>"+vbNewline Next End If processSimpleType = res + printTab(t) + "</xsd:simpleType>"+vbNewline End Function Function processGroup(poGroup, t) res = "" If poGroup.itemType = SOMITEM_ALL Then res = res + printTab(t+1) + "<xsd:all>"+vbNewline res = res + processChoiceOrSequence(poGroup, t+1) res = res + printTab(t+1) + "</xsd:all>" End If If poGroup.itemType = SOMITEM_CHOICE Then res = res + printTab(t+1) + "<xsd:choice>"+vbNewline res = res + processChoiceOrSequence(poGroup, t+1) res = res + printTab(t+1) + "</xsd:choice>" End If If poGroup.itemType = SOMITEM_SEQUENCE Then res = res + printTab(t+1) + "<xsd:sequence>"+vbNewline res = res + processChoiceOrSequence(poGroup, t+1) res = res + printTab(t+1) + "</xsd:sequence>" End If processGroup = res End Function Function processChoiceOrSequence(poGroup, t) res = "" For Each item in poGroup.particles If item.itemType = SOMITEM_ELEMENT Then res = res + printElement(item, t+1) End If If (item.itemType and SOMITEM_GROUP) = SOMITEM_GROUP Then res = res + processGroup(item, t+1)+vbNewline End If If item.itemType = SOMITEM_ANY Then res = res + "any: " + item.name+vbNewline End If Next processChoiceOrSequence = res End Function Function printElement(oElement, t) res = printTab(t) + "<xsd:element " If oElement.isReference Then res = res + "ref='" + oElement.name + "'" + printParticles(oElement) + ">" res = res + "<!-- " res = res + " abstract='" & oElement.isAbstract & "'" res = res + " -->" Else Set oType=oElement.type res = res + "name='" + oElement.name + "'" + printParticles(oElement) res = res + " abstract='" & oElement.isAbstract & "'" res = res + " id='" & oElement.id & "'" If oType.name = "" Then res = res + ">" + vbNewLine If oType.itemType = SOMITEM_COMPLEXTYPE Then res = res + printElement + processComplexType(oType, t+1) Else res = res + processSimpleType(oType, t) 'res= res + "okhaha" + vbNewLine End If res = res + printTab(t) + "</xsd:element>" Else If printName(oType) <> "xsd:anyType" Then res = res + " type='" + printName(oType) + "'" End If If oType.itemType <> SOMITEM_COMPLEXTYPE Then If printRestrictions(oType, 0) = "" Then res = res + "/>" Else res = res + ">" + vbNewLine + processSimpleType(oType, t) res = res + printTab(t) + "</xsd:element>" End If Else 'res = res + ">" + vbNewLine + processComplexType2(oType, t) res = res + printTab(t) + "</xsd:element>" End If End If End If rem = "scope:" & printName(oElement.scope) res = res + printRemark( "rem" ) printElement = res End Function Function printParticles(oParticle) If oParticle.minOccurs <> 1 Then res = res + " minOccurs='" & oParticle.minOccurs & "'" End If If oParticle.maxOccurs <> 1 Then If oParticle.maxOccurs = -1 Then res = res + " maxOccurs='unbounded'" Else res = res + " maxOccurs='" & oParticle.maxOccurs & "'" End If End If printParticles = res End Function Function printAttr(oAttr, t) If oAttr.isReference Then printAttr = printAttr + printTab(t) + "<xsd:attribute ref='" + oAttr.name + "'" Else printAttr = printAttr + printTab(t) + "<xsd:attribute name='" + oAttr.name + "'" End If If oAttr.type.name <> "" Then printAttr = printAttr + " type='" + printName(oAttr.type) + "'" End If If oAttr.defaultValue <> "" Then printAttr = printAttr + " default='" + oAttr.defaultValue + "'" End If If oAttr.fixedValue <> "" Then printAttr = printAttr + " fixed='" + oAttr.fixedValue + "'" End If If oAttr.use = SCHEMAUSE_OPTIONAL Then printAttr = printAttr + " use='optional'" End If If oAttr.use = SCHEMAUSE_PROHIBITED Then printAttr = printAttr + " use='prohibited'" End If If oAttr.use = SCHEMAUSE_REQUIRED Then printAttr = printAttr + " use='required'" End If printAttr = printAttr + "/>" rem = "scope:" & printName(oElement.scope) printAttr = printAttr + printRemark("rem") End Function Function printTab(t) tab="" For x=0 to t tab=tab+" " Next printTab=tab End Function Function printName(item) printName ="" If (item.itemType and SOMITEM_DATATYPE) = SOMITEM_DATATYPE Then printName= "xsd:" End If If item.itemType = SOMITEM_ANYTYPE Then printName= "xsd:" End If printName= printName + item.name End Function Function printRestrictions(oType, t) res = "" If oType.minExclusive <> "" Then res = res + printTab(t+1) + "<xsd:minExclusive value='"+ oType.minExclusive + "'/>" + vbNewLine End If If oType.minInclusive <> "" Then res = res + printTab(t+1) + "<xsd:minInclusive value='"+ oType.minInclusive + "'/>" + vbNewLine End If If oType.maxExclusive <> "" Then res = res + printTab(t+1) + "<xsd:maxExclusive value='"+ oType.maxExclusive + "'/>" + vbNewLine End If If oType.maxInclusive <> "" Then res = res + printTab(t+1) + "<xsd:maxInclusive value='"+ oType.maxInclusive + "'/>" + vbNewLine End If If oType.totalDigits > -1 Then res = res + printTab(t+1) + "<xsd:totalDigits value='" & oType.totalDigits & "'/>" + vbNewLine End If If oType.fractionDigits > -1 Then res = res + printTab(t+1) + "<xsd:fractionDigits value='" & oType.fractionDigits & "'/>" + vbNewLine End If If oType.length > -1 Then res = res + printTab(t+1) + "<xsd:length value='" & oType.length & "'/>" + vbNewLine End If If oType.minLength > -1 Then res = res + printTab(t+1) + "<xsd:minLength value='" & oType.minLength & "'/>" + vbNewLine End If If oType.maxLength > -1 Then res = res + printTab(t+1) + "<xsd:maxLength value='" & oType.maxLength & "'/>" + vbNewLine End If If oType.enumeration.length > 0 Then For each item in oType.enumeration res = res + printTab(t+1) + "<xsd:enumeration value='" + item + "'/>" + vbNewLine Next End If If oType.whitespace > 0 Then res = res + printTab(t+1) + "<xsd:whitespace value='" & oType.whitespace & "'/>" + vbNewLine End If If oType.patterns.length > 0 Then For Each pattern in oType.patterns res = res + printTab(t+1) + "<xsd:pattern value='" + pattern + "'/>" + vbNewLine Next End If printRestrictions = "" If res <> "" Then 'printRestrictions = printRestrictions + printTab(t) + "<xsd:restriction base='" + printName(oType.baseTypes(0)) + "'>" + vbNewLine printRestrictions = printRestrictions + printTab(t) + "<xsd:restriction base='" + "'>" + vbNewLine printRestrictions = printRestrictions + res printRestrictions = printRestrictions + printTab(t) + "</xsd:restriction>" + vbNewLine End If End Function Function printRemark(r) If remarks = 1 Then printRemark = "<!-- " + r + " -->" End If printRemark = printRemark + vbNewLine End Function '///////////////////////////////////////////////////////////////////// Main.xml <?xml version="1.0" encoding="UTF-8"?> <MN:ECase xmlns:MN="http://www.test.com/ok" xmlns:XSI="http://www.w3.org/2001/XMLSchema-instance"> <MN:test MyElementIndexBegin="1" MyElementIndexEnd="2"> <MN:OneMan MyElementIndexBegin="3" MyElementIndexEnd="4" XSI:type="MN:Man" > <MN:Name MyElementIndexBegin="5" MyElementIndexEnd="6">Mr_A</MN:Name> <MN:Power curCursorIn="sss" MyElementIndexBegin="5" MyElementIndexEnd="6">300Pounds</MN:Power> </MN:OneMan> <MN:ok>haha</MN:ok> </MN:test> </MN:ECase> thanks Best Regards F.Beyond -----ÓʼþÔ¼þ----- ·¢¼þÈË: fc_·½³¬ ·¢ËÍʱ¼ä: 2003Äê5ÔÂ6ÈÕ 9:38 ÊÕ¼þÈË: xml-dev@l... ³ËÍ: ht@c... Ö÷Ìâ: new import problem Sorry,I post a wrong message. I forget to add a new namespace in the Second file. So I added it this time.but the question is the same. The parser said "it is invalid derived from restriction particle,base type:'{http://www.test.com/}Man,derived type:'{http://www.test.com/ok>}SuperMan' When I use the whole document,it will not cause any problem.and everythings are OK <xs:schema xmlns:dn="http://www.test.com/ " xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:simpleType name="PowerEnum¡±> <xs:restriction base="xs:string"> <xs:enumeration value="1Pounds"/> <xs:enumeration value="2Pounds"/> <xs:enumeration value="300Pounds"/> </xs:restriction> </xs:simpleType> <xs:complexType name="Man" abstract="true"> <xs:sequence> <xs:element name="Name" type="xs:string"/> <xs:element name="Power" type="PowerEnum"/> </xs:sequence> </xs:complexType> <xs:complexType name="SuperMan"> <xs:complexContent> <xs:restriction base="Man"> <xs:sequence> <xs:element name="Name" type="xs:string"/> <xs:element name="Power"> <xs:simpleType> <xs:restriction base="PowerEnum"> <xs:enumeration value="1Pounds "/> <xs:enumeration value="2Pounds "/> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> </xs:restriction> </xs:complexContent> </xs:complexType> <xs:element name="test"> <xs:complexType> <xs:sequence> <xs:element name="OneMan" type="SuperMan"/> <xs:element name="ok" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> but when I use the separate document,error occurred:parser(MS XML SDK)said I couldn¡¯t use restriction to derive in main_derive.xsd main.xsd <xs:schema targetNamespace="http://www.test.com/" xmlns="http://www.test.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:simpleType name="PowerEnum"> <xs:restriction base="xs:string"> <xs:enumeration value="1Pounds"/> <xs:enumeration value="2Pounds"/> <xs:enumeration value="300Pounds"/> </xs:restriction> </xs:simpleType> <xs:complexType name="Man" abstract="true"> <xs:sequence> <xs:element name="Name" type="xs:string"/> <xs:element name="Power" type="PowerEnum"/> </xs:sequence> </xs:complexType> </xs:schema> main_derive.xsd <xs:schema xmlns="http://www.test.com/ok" targetNamespace="http://www.test.com/ok" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:im="http://www.test.com/" elementFormDefault="qualified"> <xs:import namespace="http://www.test.com/" schemaLocation="main.xsd"/> <xs:complexType name="SuperMan"> <xs:complexContent> <xs:restriction base="im:Man"> <xs:sequence> <xs:element name="Name" type="xs:string"/> <xs:element name="Power"> <xs:simpleType> <xs:restriction base="im:PowerEnum"> <xs:enumeration value="300Pounds"/> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> </xs:restriction> </xs:complexContent> </xs:complexType> <xs:element name="test"> <xs:complexType> <xs:sequence> <xs:element name="OneMan" type="SuperMan"/> <xs:element name="ok" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> sorry for consume all of ur time. Best Regards fbeyond -----ÓʼþÔ¼þ----- ·¢¼þÈË: Henry S. Thompson [mailto:ht@c...] ·¢ËÍʱ¼ä: 2003Äê4ÔÂ30ÈÕ 17:40 ÊÕ¼þÈË: fc_·½³¬ ³ËÍ: xml-dev@l... Ö÷Ìâ: Re: import problem =?utf-8?B?ZmNf5pa56LaF?= <fangc@b...> writes: > Hi,I got a namespace problem. You're using import for a schema document with the same target namespace as the importing document -- you should be using include. See the W3C XML Schema Primer [1] for an example. ht [1] http://www.w3.org/TR/xmlschema-0/#SchemaInMultDocs -- Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh Half-time member of W3C Team 2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440 Fax: (44) 131 650-4587, e-mail: ht@c... URL: http://www.ltg.ed.ac.uk/~ht/ [mail really from me _always_ has this .sig -- mail without it is forged spam] ----------------------------------------------------------------- The xml-dev list is sponsored by XML.org <http://www.xml.org>, an initiative of OASIS <http://www.oasis-open.org> The list archives are at http://lists.xml.org/archives/xml-dev/ To subscribe or unsubscribe from this list use the subscription manager: <http://lists.xml.org/ob/adm.pl>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|