How do i build namespaces xmlns, xmlns:xsi, and schema xsi:schemalocaton in my XML via VB.net? -


i need replicate xml header:

<xdatafeed  xmlns="http://foo.com/namespace"  xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" . xsi:schemalocation="http://foo.com/namespace c:\fooxsd.xml"> 

with code:

'export object xml                 dim writer new xmlserializer(datafeed.gettype)                 dim ns new xmlserializernamespaces()                 ns.add("xmlns", "http://foo.com/namespace")                 ns.add("xsi", "http://www.w3.org/2001/xmlschema-instance")                 dim file new system.io.streamwriter("c:\foo.xml")                 writer.serialize(file, datafeed, ns)                 file.close() 

and i'm hitting 2 issues:

  1. when try add namespace without prefix foo.com, removes namespaces. code above adds foo.com's namespace as:

    xmlns:xmlns="http://foo.com/namespace"

which not correct. how add in namespace without prefix?

  1. i have searched hour trying figure out how append attribute "xsi:schemalocation..." xml, though every single example found uses types in c#, or manipulation declared xml doc not aplicable vb.net xmlserializer approach. how go appending schemalocation attribute xml way of xmlserializer code above?

i appreciate assistance. need xml pass through via xsd validation approved, , final piece standing in way.

just had myself.

don't add namespace xmlserializernamespaces. instead, put on parent object. should make not have prefix , xmlns="http://...".

<xmlroot(namespace:="http://foo.com/namespace")> public class xdatafeed     '... end class 

if reason slaps in dummy prefix d1p1, use string.empty prefix , go ahead , add namespace xmlserializernamespaces.

in order schemalocation show up, can create dummy property , tag accordingly:

<xmlattribute("schemalocation", namespace:=xmlschema.instancenamespace)> public property schemalocation string             return "http://foo.com/namespace c:\fooxsd.xml"     end     set(value string)         'ignore... pureley needed serialization.     end set end property 

you adding in xsi namespace should work fine if keep doing that. take out xmlns namespace.

in end should end class this:

<xmlroot(namespace:="http://foo.com/namespace")> public class xdatafeed      <xmlattribute("schemalocation", namespace:=xmlschema.instancenamespace)>     public property schemalocation string                     return "http://foo.com/namespace c:\fooxsd.xml"         end         set(value string)             'ignore... pureley needed serialization.         end set     end property  end class 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -