Hi,

XML Schema depends on namespaces. Document.createElement() and
Element.setAttribute() create non-namespace-aware element and attribute
nodes which are missing a local name and namespace URI. You should never
use the DOM Level 1 non-namespace factory methods with a DOM containing
namespace-aware nodes (or with APIs expecting namespace-aware nodes). New
element/attribute nodes should be created by calling
Document.createElementNS() [1] and Element.setAttributeNS() [2].

e.g. document.createElement("s:import")
 --> document.createElementNS("http://www.w3.org/2001/XMLSchema";,
"s:import")

Thanks.

[1]
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
[2]
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-ElSetAttrNS

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

Nataliya <[EMAIL PROTECTED]> wrote on 03/18/2008 07:46:41 AM:

> Hello,
>
> thank you very much for the answer!
>
> I included the recommended line in my file and saw that it solved
> the problem. As I already mentioned, I don't want to edit the files
> manually, so I want to append the necessary information in form of a
node.
> I tried the following:
>
> ....Element rootSchemaElement = getSchemaElementFromDefinition(def);
>     Document document = rootSchemaElement.getOwnerDocument();
>     Element newNode = document.createElement("s:import");
>
>     newNode.setAttribute("namespace",
"http://www.w3.org/2001/XMLSchema";);
>     newNode.setAttribute("schemaLocation", "http://www.w3.
> org/2001/XMLSchema.xsd");
>
>    schemaElement.insertBefore(newNode,
schemaElement.getChildNodes().item(1));
>
> //As alternative  to: schemaElement.insertBefore(newNode,
> schemaElement.getChildNodes().item(1));
> //I tried also: schemaElement.appendChild(newNode);
>
> I checked (with get-Methods), if the attributes are set and if the
> NodeName is the proper one, the answer was positive. But if I insert
> (append) the node and parse the schema I get the following error:
>
> [Error] :-1:-1: s4s-elt-invalid-content.1: The content of 'schema'
> is invalid.  Element 's:import' is invalid, misplaced, or occurs too
often.
>
> I tried to change the number of the item, to which I append, it
> doesn't help. So the element is likely to be invalid.
>
> What am I doing wrong? I think, that something is absent in this
> node, but I don't know what; maybe it is some character or a symbol,
> that the tag is closed...
>
> I want only to add the following information to the schema: <s:
> import namespace="http://www.w3.org/2001/XMLSchema"; schemaLocation="
> http://www.w3.org/2001/XMLSchema.xsd"/>
>
> Thanks
>
> Best regards,
> Nataliya
>
> Michael Glavassevich schrieb:
> Hi Nataliya,
>
> The schema document embedded in your WSDL is missing a required import:
>
> <s:import namespace="http://www.w3.org/2001/XMLSchema";
> schemaLocation="http://www.w3.org/2001/XMLSchema.xsd"/>
>
> This isn't just a validation error. The XSModel you've built is missing
> components. If you want to resolve this issue you need to add the import
to
> the document. If you don't want to edit the file on disk you could add it
> to the DOM in memory before passing the schema root Element node to the
> XMLGrammarPreparser.
>
> The entity resolver gives your application an opportunity to do custom
> resolution of schemaLocations (e.g. redirecting to a local copy of
> XMLSchema.xsd) on includes/imports/redefines. There's an FAQ [1] on the
XML
> Catalog
>  resolver with some examples on the Xerces-J website. Note that it
> won't be called in this case unless you have an import for the
> "http://www.w3.org/2001/XMLSchema"; namespace in your schema.
>
> Thanks.
>
> [1] http://xerces.apache.org/xerces2-j/faq-xcatalogs.html
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: [EMAIL PROTECTED]
> E-mail: [EMAIL PROTECTED]
>
> Nataliya <[EMAIL PROTECTED]> wrote on 03/17/2008 02:23:32 PM:

> Hello dear users and developers!
>
> I have a great problem while parsing some XML-Schemas. My task is to
> extract the information from WSDL-Files and parse an included schema as
> well.
>
> I read about "Using XML Schema", "Caching & Preparsing Grammars" and
> some of the threads in the mailing-list. I saw, that some people had
> similar problems, but I can't resolve mine.
>
> So, I parse the wsdl-File with wsdl4j and
>  extract the schema-Element
> from it.
>
> Then I want to use the Methods of XSModel, which offer all the
> possibilities to extract the necessary information.
>
> Because of the line "<s:element ref="s:schema" />" in the schema (in my
> example) I have a problem and the following error:
>
> [Error] :-1:-1: src-resolve.4.2: Error resolving component 's:schema'.
> It was detected that 's:schema' is in namespace
> 'http://www.w3.org/2001/XMLSchema', but components from this namespace
> are not referenceable from schema document 'file:/C:/MyData/test.wsdl'.
> If this is the incorrect namespace, perhaps the prefix of 's:schema'
> needs to be changed. If this is the correct namespace, then an
> appropriate 'import' tag should be added to 'file:/C:/MyData/test.wsdl'.
>
> I don't want to make some changes in the wsdl-File, because the
> validation is not important for me, my task is to analyse the existing
> files and not to improve them. The most
>  confusing thing is that the
> parser extracts everything what I want from the schema element (i.e. it
> runs without to stop), but I see this validation error all the time.
>
> I don't want to validate! I want to extract! What can I do in this case?
> Can I turn off the validation feature and get an XSModel anyway? Can I
> turn off the reporting of the validation errors?
>
> Can some art of resolver help in this case? Can I say: if s:schema
> appears, the "http://www.w3.org/2001/XMLSchema"; schould be used? I don'd
> understand the feature setEntityResolver... Can anybody give some
> samples? Could I use some default resolvers or the resolvers in
> resolver.jar? How can I do this?
>
> Please, help me!
>
> Best regards,
> Nataliya
>
>
>
> Here is some Code for better undestanding:
>
>     WSDLFactory factory = WSDLFactory.newInstance();
>     WSDLReader reader = factory.newWSDLReader();
>
>     reader.setFeature("javax.wsdl.verbose",
>  true);
>     reader.setFeature("javax.wsdl.importDocuments", true);
>
>     String urlToWSDLFile = "C:/MyData/test.wsdl";
>     Definition def = reader.readWSDL(urlToWSDLFile);
>     Element rootSchemaElement = getSchemaElementFromDefinition(def);
>     DOMInputSource domInput = new DOMInputSource(rootSchemaElement);
>
>     XMLGrammarPreparser xmlGrammarPreparser = new XMLGrammarPreparser();
>
>

>
xmlGrammarPreparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA,null);


>     XMLGrammarLoader schemaLoader =
> xmlGrammarPreparser.getLoader(XMLGrammarDescription.XML_SCHEMA);
>
>
>     try {
>
>         Grammar preparseGrammar =
> xmlGrammarPreparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA,
> domInput);
>
>         XSGrammar xsGrammar = (XSGrammar) preparseGrammar;
>
>         XSModel xsModel = xsGrammar.toXSModel();
>
>
>  getElementsFromSchema(xsModel);
>
> ......................
>
>
> ___________________________________________________________
> Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to