0

I'm attempting to create a test framework in c# to automate some of our API tests. Relatively new to this area so have come across an issue I can't solve. My XML payload is as below:

 <Order>
   <BillingAddress>
     <AddressLine1></AddressLine1>
     <AddressLine2></AddressLine2>
     <City></City>
   </BillingAddress>
  <Items>
    <Item IsKit="false">
      <CountryVATRate></CountryVATRate>
      <Group></Group>
      <Reference></Reference>
 </Item>
 </Items>
</Order>

When I attempt to execute the above(using RestSharp) I get the below error: "System.Xml.XmlException: 'The ' ' character, hexadecimal value 0x20, cannot be included in a name.'"

The offending line of code is

        <Item IsKit="false">

...where the code in c# I have written is as below

        XElement items = new XElement("Items");
        items.Add(new XElement("Item IsKit =\"false\""

I believe the issue is because there are spaces between the words 'Item' and 'IsKit'....my question is how I would get around this in order for this element to be added to my test code?

  • Your Items tag is not closed and might be causing the issue. – Dakshinamurthy Karra Oct 3 '18 at 11:45
  • sorry I didn't put the closing tag in the code example above. thanks for pointing that out, however I still have the original issue – Andy Tilston Oct 3 '18 at 12:01
2

you are trying to make an element called 'Item IsKit =\"false\"'

it looks like you actually want to create an Element called Item with an attribute called IsKit.

Try this:

new XElement("Item",new XAttribute("IsKit", "False"))

Docs are here https://docs.microsoft.com/en-us/dotnet/api/system.xml.linq.xattribute

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.