Solved

Sending <CapturePayment /> as XML using Serialize

Posted on 2013-10-28
11
469 Views
Last Modified: 2013-10-29
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!
0
Comment
Question by:Starr Duskk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39608820
Can you show the schema that you are working with?
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39608907
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
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39608915
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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 39608949
What are you using to serialize the XML?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39608982
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
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39609040
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
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39609043
      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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39609325
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
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39609620
As indicated in my first message, I already tried xs:string.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39609762
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
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39609782
ok. thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question