Prefix <ns: before all elements from a document type generate from a xml schema

Hello,

Sorry for my “english speech”, i am french.

I have a problem with a document type generate from a xml schema.
All the elements begins with the prefix <ns:

XML Schema beginning :
<xsd:schema targetNamespace=“http://xxxxx” xmlns=“http://xxxxx” xmlns:xsd=“XML Schema” elementFormDefault=“qualified” attributeFormDefault=“unqualified”>

As you can note it, no prefix is defined !!

I must generate a xml string with the method
“pub.xml:documentToXMLString” but the elements should not be prefixed.

How can I to remove this prefix ?

In advance thank you and i am sorry if I did not see that somebody already posted this problem

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.

Hope that helps,

Mark

when you generate the xmlString the prefixes disappear automatically…

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 :
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsd:schema targetNamespace=“http://xxxxx” xmlns=“http://xxxxx” xmlns:xsd=“XML Schema” elementFormDefault=“unqualified” attributeFormDefault=“unqualified”>
<xsd:element name=“test” type=“xsd:string”/>
</xsd:schema>

The document type is :
ns:test

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsd:schema xmlns=“http://xxxxx” xmlns:xsd=“XML Schema” elementFormDefault=“qualified” attributeFormDefault=“unqualified”>
<xsd:element name=“test” type=“xsd:string”/>
</xsd:schema>

The document type is :
test

It’s this result which I wait… but I don’t want to modify the schema.

Is it possible to generate it without taking into account of the namespace ?

for Arnaud : when I use the function “documentToXMLString” the prefix doesn’t disappear… perhaps I don’t use the good function?

I generate a doc type from an XSD and i get this:

-ns:note
—ns:to
—ns:from
—ns:heading
—ns:body

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

and i get a document like this without the ns

-document
@version
—/note
------to
------from
------heading
------body

it works for me… or i haven’t understand your problem :smiley:
(mais lache pas tu vas y arriver ^^)

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” ?

ok now i understand i think :wink:

you can create an other document type perhaps, exactly the same like the one with your "ns’ prefix but without this prefix and do a mapping.

ns:xxx
—ns:yyy
—ns:www

to

xxx
—yyy
—www

and then generate the xml string :rolleyes:

or you can cheat by replacing all the “<ns:” with “<” and “</ns:” with “</” in you xmlString…

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=“unqualifiedand 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 :frowning:

it’s a pity that one cannot change the default prefix “ns” which is coded into hard in the software…

Thank you

Since the prefix is just an arbitrary shorthand namespace pointer, it should not matter. It could be mickymouse instead of ns.

In your original post

 
 
XML Schema beginning : 
<xsd:schema targetNamespace="http://xxxxx" xmlns="http://xxxxx" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
.......

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?

This thread closely matches my issue.

I am using 6.5.

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:

  1. create an IS document from the xml schema that has a default namespace. This produces documents with the ns:

  2. convert the incomming xml string using xmlStringToXMLNode

  3. 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.

  4. 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.

------------Possible XML input

<?xml version="1.0" encoding="UTF-8"?>

<comp:Policy xmlns:comp=“http://www.xyz” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://www.xyz”>
comp:PolicyNumberPolicyNumber</comp:PolicyNumber>
comp:LOBCdtoken</comp:LOBCd>
</comp:Policy>

---------------Convert to Doc

ns:Policy
ns:Policynumber
ns:LOBCd

----------Convert to XML with no namespace prefix (HAVEN’T BEEN ABLE TO DO YET!)

<?xml version="1.0" encoding="UTF-8"?>

<comp:Policy xmlns=“http://www.xyz” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://www.xyz”>
PolicyNumber
token

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.

Mark

Thanks for the reply.

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.

Maybe we should back up a bit. Why do you need to remove the namespace prefixes and namespace declarations from a perfectly valid XML document?

Mark

Why do I want to remove the prefixes…

  1. We want to accept xml from external customers with whatever prefixes they use (as long as the namespace is correct obviously)
  2. 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.

Mark

lol… exactly.

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:

<xsd:schema targetNamespace=“http://www.xxx.myOrg” elementFormDefault=“unqualified” attributeFormDefault=“unqualified” xmlns:xsd=“XML Schema” xmlns=“http://www.xxx.myOrg”>