The elementFormDefault=“qualified” attribute of your schema indicates that the elements should be namespace-qualified. IS is performing correctly by adding the prefix to the document and its fields.
If you had set the targetNamespace and then also associated a prefix with that same namespace, you would have seen IS use a prefix other than the default value of “ns”.
Change elementFormDefault=“qualified” to elementFormDefault=“unqualified” to change this behavior.
Your English is perfectly fine and your question shows that you thought about it before posting. Thanks, thats a nice change to many posts we’ve seen around here lately.
I can’t modify the schema because I work on a project which uses official schemas, I would have to specify it earlier to you !!! My project is complex because it use 28 imbricated schemas.
But I made a small example to test various cases :
I change elementFormDefault=“qualified” to elementFormDefault=“unqualified”
Xml schema :
then i use
pub.xml:xmlStringToXMLNode to convert my string contening the xml to a node
then pub.xml:xmlStringToDocument with documenttypename=the_name_of_the_doctype_generated
Approximately my program search information in a database, then it fills the document type and then it must generate the xml string.
Consequently i don’t have a string who contains the xml, the document type already contains the informations and then i must generate the xml string. This is why I would like to use the function “documentToXMLString”
I hope that you better understand my problem, I would like to avoid using too much function of conversion.
I don’t know the function “pub.xml:xmlStringToDocument”, i think that you speak about this function “pub.xml:xmlNodeToDocument” ?
The document is too much complex because it use 28 imbricated schemas.
The second solution is good but it isn’t very “clean”.
An other problem appears if i must publish this document to the broker.
The ideal would be to generate a document type without taking into account of the namespace…
I again tried to change
elementFormDefault=“qualified” to elementFormDefault=“unqualified” and all the nodes are not prefixed any more except the node root. Mark you are right :).
Finally, i do not have an other choice only to modify the schema
it’s a pity that one cannot change the default prefix “ns” which is coded into hard in the software…
You say there is no prefix, but that’s because it’s using a default namespace which means any unqualified element (without a prefix) under the root node will belong to the default namespace.
elementFormDefault=“qualified” simply means as Mark C. stated that the elements must be namespace qualified. You don’t have to use a prefix to do that if you use a default namespace which your example above does.
Both ways are correct and the consuming software should be able to handle either way. .Net uses the default namespace instead of fully qualifying each individual element while most java base implementations I’ve seen tend to go toward the fully qualified (using a prefix on each element). Both ways are correct and the consuming software should be able to handle it.
Prefix is whatever you set it to in this case using the nsDecls parameter.
I’m not sure from your post that I follow why the prefix is causing you problems. Is it some outbound XML you are sending that has the embedded prefix in it that a client is having trouble with? Could you give a little more detail on that?
My goal is to take in xml that may have a namespace prefix specified, map it out, do some editing, map it back to the same document type, and convert to xml but without a namespace prefix.
Is it possible to use documentToXMLString to convert a IS document with a declared namespace to xml using the default namespace?
So far my steps have been the following:
create an IS document from the xml schema that has a default namespace. This produces documents with the ns:
convert the incomming xml string using xmlStringToXMLNode
convert the node to a document using xmlNodeToDocument, setting the documentTypeName as the document created from the schema import, and the nsDecls set value = ns: and the name = to the targetnamespace specified in the schema.
for purposes of this discussions, I essentially now want to convert the document into xml with out any namespace prefixes. Using documentToXMLString allows me to set the nsDecls to what I want, but I want it to be blank.
One approach is to create another version of the IS doc type which does not have the “ns:” prefixes on the variable names. Map to this one from the original one and then create an XML string from the new one.
If you are creating a XML string from an IS doc type whose variables contain prefixes, I do not know of a way to cause it to ignore those prefixes.
I thought of doing that. Is this a common approach?
These documents will be very large (100-300 attributes depending on how much optional data is being sent). I assume as long as I drop the orginal ns: doc once mapped I won’t risk too much memory overhead.
We want to accept xml from external customers with whatever prefixes they use (as long as the namespace is correct obviously)
Our downstream system requires no prefixes to be used.
I thought about mapping the document with ns to one with out the ns. I think there is way to much overhead in that and we would have to maintain both document types, which are enormous.
I would think there should be a way to set the namespace prefix on the way out just as we can on the way in. In my case set it to nothing.
I am now leaning towards just doing a string replace on the entire xml as mentioned before in this thread.
What kind of application accepts valid XML but not valid XML documents containing prefixes? I’m sure its some legacy beast that you don’t have control over.
If you create your IS doc type with prefixes, then any XML string you create from that doc type will contain prefixes as the names of the variables in the doc type are used to create the tags.
It is possible to modify your XML schema used to create the doc type so that it does not namespace-qualify elements and attributes. Specify the elementFormDefault=“unqualified” attribute in your XML schema. Then when you generate the doc type from the schema, it will not contain the “ns:” prefixes.
i modified the schema to elementFormDefault=“unqualified”, and then created the IS doc using the schema. It still creates it with the “ns:” prefix. I’ve tried this numerous times with many variations… maybe you see something I’m missing: