xml - Java Jaxb : unexpected element (uri:"", local:"Create"). Expected elements are -


मुझे अपने जेएसीएबी

  & lt; element name = "create" & gt के साथ समस्या है ; & LT; complexType & gt; & LT; अनुक्रम & gt; & Lt; element name = "name" प्रकार = "string" & gt; & lt; / element & gt; & Lt; / अनुक्रम & gt; & Lt; / complexType & gt; & Lt; / तत्व & gt;   

मेरा XML:

  & lt; बनाएं & gt; & LT; नाम & gt; कोको & lt; / name & gt; & Lt; / बनाएं & gt;   

मेरा कोड java:

  JAXBContext संदर्भ = JAXBContext.newInstance ("MyPackage"); Unmarshaller decodeur = context.createUnmarshaller (); System.out.println ("पाठ:" + संदेश); MsgObject = decodeur.unmarshal (sr); अगर (msgObject उदाहरण का निर्माण करें) {System.out.println ("क्रिया"); }   

और मेरे पास यह है:

अनपेक्षित तत्व (यूरी: "", स्थानीय: "बनाएं") अपेक्षित तत्व & lt; {} बनाते हैं & gt;

और मेरा कोड इसे रोकता है:

  msgObject = decodeur.unmarshal (sr);   

मेरा एक्सएमएल अच्छा है? , क्या आप मेरी मदद कर सकते हैं, क्योंकि मुझे नहीं पता कि समस्या क्या है

आपकी एक्सएमएल स्कीमा शायद एक है स्कीमा टैग निम्न की तरह है।

  & lt;? xml संस्करण = "1.0" एन्कोडिंग = "UTF-8"? & gt; & Lt; स्कीमा xmlns = "http://www.w3.org/2001/XMLSchema" targetNamespace = "http://www.example.org/XSD_Maths" xmlns: tns = "http://www.example.org/ XSD_Maths "elementFormDefault =" qualified "& gt;   

चूंकि यह targetNamespace का http://www.example.org/XSD_Maths निर्दिष्ट करता है। आपका XML निम्न की तरह दिखना होगा:

  & lt; create XMLml = "http://www.example.org/XSD_Maths" & gt; & LT; नाम & gt; कोको & lt; / name & gt; & Lt; / बनाने & gt;   

एक DOM से unmarshalling के बारे में नोट

यदि आप एक DOM document या Element से unmarshalling सुनिश्चित करें कि आपके द्वारा उपयोग किया गया डोम पार्सर नाम का स्थान पता था। यह DocumentBuilderFactory पर निम्न ध्वज सेट करके किया जाता है।

  documentBuilderFactory.setNamespaceAware (सत्य);   

अधिक जानकारी के लिए

नीचे मेरे ब्लॉग पर एक आलेख का एक लिंक है, जहां मैं जेएसीएबी और नामस्थान के बारे में अधिक गहराई में जाता हूं।

    < li>

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -