locked
XML namespace - include as prefix RRS feed

  • Question

  • Hi all,

    I have an object I am serializing and instead of the XML looking like this:

    <Rule source="123" value="temp" xmlns="http://temp.com/msg/pri">
    
    
    I want the xml namespace to be included as a prefix to the element like this:

    <pri:Rule source="123" value="temp" xmlns="http://temp.com/msg/pri">
    
    
    Is there any way I can force the serialization to include this?

    Thanks,
    Billy
    • Edited by wallaceoc Wednesday, August 19, 2009 3:13 PM
    Wednesday, August 19, 2009 9:35 AM

Answers

  • The following two XML elements are identical:

    <Rule source="123" value="temp" xmlns="http://temp.com/msg/pri">
    
    and

    <pri:Rule source="123" value="temp" xmlns:pri="http://temp.com/msg/pri">
    
    If any of the applications you are sending data to does not know that these two are identical, then those applications have a bug, and the bug needs to be fixed. It is a mistake for you to break your application in order to work around a bug in another application.

    The power and success of XML is that it is a single, coherent set of standards. By enabling the applications we communicate with to each use its own version of XML, we are destroying the value of XML, and moving back towards the bad old days when half the effort of a project was to make the pieces work together.
    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    • Marked as answer by wallaceoc Thursday, August 20, 2009 11:56 AM
    Wednesday, August 19, 2009 3:51 PM
    Moderator

All replies

  • Actually, what you want is

    <pri:OfferingRule source="123" value="temp" 
        xmlns:pri="http://temp.com/msg/pri">
    
    May I ask why you want it this way? It's equivalent to the other way, except that you seem to have changed the element name.


    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Wednesday, August 19, 2009 12:32 PM
    Moderator
  • Thanks for your response...  That was a type (which I've now corrected) - the message I want should have read <pri:Rule......>

    i.e. I replace the xmlns="..." text by prefixing the element name with the namspace.

    Is this possible to do?  Some of the apps I feed the message to are failing on deserialization without the namespace prefix even tho we both use the same schema definition.

    Thanks

    Wednesday, August 19, 2009 3:16 PM
  • The following two XML elements are identical:

    <Rule source="123" value="temp" xmlns="http://temp.com/msg/pri">
    
    and

    <pri:Rule source="123" value="temp" xmlns:pri="http://temp.com/msg/pri">
    
    If any of the applications you are sending data to does not know that these two are identical, then those applications have a bug, and the bug needs to be fixed. It is a mistake for you to break your application in order to work around a bug in another application.

    The power and success of XML is that it is a single, coherent set of standards. By enabling the applications we communicate with to each use its own version of XML, we are destroying the value of XML, and moving back towards the bad old days when half the effort of a project was to make the pieces work together.
    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    • Marked as answer by wallaceoc Thursday, August 20, 2009 11:56 AM
    Wednesday, August 19, 2009 3:51 PM
    Moderator
  • Hi John,

    thanks for your replies... I think I found the problem and it wasn't related to the namespaces in the end.  All working good now with no bugs hanging around.

    Cheers!!!
    Thursday, August 20, 2009 11:56 AM