6

Does anyone have worked with cXML and C#?

I'm working in a project that will need to create cXML files (integration will Dell's electronic Purchase Ordering system) and have found some libs like this one, but now I wonder if anyone here has another ideia of how to create those files.

Thanks!

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
wtaniguchi
  • 1,324
  • 14
  • 22

3 Answers3

14

http://cxml.org/files/downloads.html

Go here and download the DTD file. Then open the document in Visual Studio (2013) and go to XML menu at the top and click "Create Schema". This will make an XSD file. Save it somewhere. Then use the VS Developer Command prompt, navigate to the directory where you just saved your XSD file and execute this command:

"xsd.exe filename.xsd /classes /language:CS"

It will then generate a CS file containing all of the cXML classes that you can reference in your project.

Rafiki
  • 630
  • 1
  • 8
  • 22
  • 1
    Thanks for that :) However I wasn't able to use that approach to generate classes for latest version (Version 1.2.031). Works fine if you want to generate (Version 1.1.010) – user3455363 Oct 26 '16 at 16:09
  • 1
    I can't recall which version we used, but one problem I did run into was it created every possible class off of that XSD file and somewhere deep in the generated class, something was missing to where it wouldn't compile properly. I ended up removing chunks of unused classes until I got down to a bare minimum which worked. I know that's probably not helpful, but if you're getting compiler errors and you're sure your API won't be using those classes, gut them. – Rafiki Oct 28 '16 at 19:02
  • Thanks for further info I think that will be my fallback option :) Atm I stick with Version 1.1.010 schema because 3rd party that I'm integrating it for is compatible with that version and it uses very small subset of cXML elements. – user3455363 Oct 31 '16 at 13:57
  • @Rafiki, thank you for the great hint to create a CS file via XSD. Could you point me to a resource on how you would work with the CS file containing the cXML classes as a reference? – jrn Jan 02 '18 at 21:27
  • thanks, worked fine also in 2021 (VS2019) – Thomas Adrian Aug 19 '21 at 06:43
5

I may add that since cXML v1.1.xx, there is a new Digital Signature stuff in it that will prevent XSD from creating the classe file. It should return an error like "

The element 'uri:ds:Signature' is missing.

"

However, you can take a look HERE : just remove that line from the XSD.

Simon
  • 2,266
  • 1
  • 22
  • 24
  • For cxml to c# model deserialization to function properly also remove the target namespace from the xsd. Check out this link for more info: https://stackoverflow.com/a/61933481/3734560 – Jasper May 21 '20 at 20:39
  • thanks, worked fine also in 2021 (VS2019) – Thomas Adrian Aug 19 '21 at 06:44
2

Well, cXML is based on XML, so you could use XmlWriter, XmlDocument, XDocument (Linq to XML), or even XML serialization if you want an object model of the document

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
  • Yeah, guess I don't much of a choice here. I will use XmlDocument and its related classes, then validate it against cXML's DTD. – wtaniguchi Sep 08 '09 at 18:29