简体   繁体   中英

XML namespace for attributes

Question: I have an xml element + attributes, which all need to be in a namespace. I set the element + all attributes into the namespace oai, and I get:

<oai:room building="AB" rmName="001">

but the XML i need to generate should look like this:

 <oai:room oai:building="AB" oai:rmName="001">

Why does it remove the oai namespace in the attributes once I set the namespace in the xml element ? Well, I see why, but how do I stop this behaviour, since I need it otherwise?

This is the serialization class I use:

<System.Xml.Serialization.XmlElement(ElementName:="room", Namespace:="http://www.example.com")> _
    Public Rooms As New System.Collections.Generic.List(Of cRoom)


Public Class cRoom
    <System.Xml.Serialization.XmlAttribute("building", Namespace:="http://www.example.com")> _
    Public buildingAs String = ""


    <System.Xml.Serialization.XmlAttribute("rmName", Namespace:="http://www.example.com")> _
    Public rmNameAs String = ""


End Class

(oai:="www.example.com")

Try changing your attributes thus:

<System.Xml.Serialization.XmlAttribute("rmName",
    Namespace:="http://www.example.com",
    Form := XmlSchemaForm.Qualified)>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM