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?

2
  • Your Items tag is not closed and might be causing the issue. Oct 3, 2018 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 Oct 3, 2018 at 12:01

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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