Sending <CapturePayment /> as XML using Serialize

I have a block of XML I need to send to a client. I use an xsd.exe generated object to create my XML using Serialize.

I need to send one line of XML which results in being a command to tell the client to process the payment:
<CapturePayment />

How do I set my object to generate this one line?
I have tried setting it as an empty string:
 ou.CapturePayment = ""
or setting it to true:
 ou.CapturePayment = true
or setting it to nothing:
 ou.CapturePayment = Nothing

First two error. Second just excludes the line.

The empty string creates this line:
<CapturePayment xsi:type="xsd:string" />
 and errors with this:
The xsi:type attribute value 'http://www.w3.org/2001/XMLSchema:string' is not valid for the element 'CapturePayment', either because it is not a type validly derived from the type in the schema, or because it has xsi:type derivation blocked.

I also tried setting this:
      <XmlElement(IsNullable:=True)>
      Public Property CapturePayment() As Object
Which when setting it to nothing generates this and the error:
ou.CapturePayment = Nothing
   <CapturePayment xsi:nil="true" />
  <ErrorDescription>If the 'nillable' attribute is false in the schema, the 'xsi:nil' attribute must not be present in the instance.</ErrorDescription>

I know I can strip out the value:
str = Replace(str, "xsi:nil=""true"" ", "") ' strip out for CapturePayment
But is there a better way?

How do I get my object to include that line just as this? <CapturePayment />

Thanks!
LVL 2
Starr DuskkASP.NET VB.NET DeveloperAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Bob LearnedConnect With a Mentor Commented:
There might be a disconnect on my side.

"The empty string creates this line:
<CapturePayment xsi:type="xsd:string" />
"

that doesn't sound like you set the type in the .xsd file.  That would have looked like this:

<xs:element name="CapturePayment" type="xs:string" />
0
 
Bob LearnedCommented:
Can you show the schema that you are working with?
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
Here is the XML:

<?xml version="1.0" encoding="UTF-8" ?>
<OrderUpdateRequest>
   <Credentials>
      <AccountName>AccountName</AccountName>
      <Key>YOUR XML KEY</Key>
   </Credentials>
   <OrderUpdate>
      <OrderNo>102375</OrderNo>
      <StatusUpdate>
         <Status>Shipped</Status>
      </StatusUpdate>
      <CapturePayment />
   </OrderUpdate>
</OrderUpdateRequest>

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
Here is the schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:element name="OrderUpdateRequest">
      <xs:complexType>
         <xs:sequence>
            <xs:element name="Credentials">
               <xs:complexType>
                  <xs:sequence>
                     <xs:element name="AccountName" type="xs:string" />
                     <xs:element name="Key" type="xs:string" />
                  </xs:sequence>
               </xs:complexType>
            </xs:element>
            <xs:element name="OrderUpdate">
               <xs:complexType>
                  <xs:sequence>
                     <xs:element name="OrderNo" type="xs:unsignedInt" />
                     <xs:element name="StatusUpdate">
                        <xs:complexType>
                           <xs:sequence>
                              <xs:element name="Status" type="xs:string" />
                           </xs:sequence>
                        </xs:complexType>
                     </xs:element>
                     <xs:element name="CapturePayment" />
                  </xs:sequence>
               </xs:complexType>
            </xs:element>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
</xs:schema>

Open in new window

0
 
Bob LearnedCommented:
What are you using to serialize the XML?
0
 
Bob LearnedCommented:
I see that CapturePayment does not have any type in the XSD.  Is this supposed to be a "presence" element to indicate the operation desired (with no other children or attributes?
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
Yes.

>>I need to send one line of XML which results in being a command to tell the client to process the payment:
<CapturePayment />
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
      Public Shared Function SerializeAnObject(AnObject As Object) As String
         Dim Xml_Serializer As New XmlSerializer(AnObject.[GetType]())
         Dim Writer As New StringWriter()
         Xml_Serializer.Serialize(Writer, AnObject)
         Return Writer.ToString()
      End Function

Open in new window

0
 
Bob LearnedCommented:
If CapturePayment is an element in the schema, what should the type be?  You might want to try as xs:string, and see how that is generated.
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
As indicated in my first message, I already tried xs:string.
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
ok. thanks.
0
All Courses

From novice to tech pro — start learning today.