Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Other Things Gentoo
  • Search

Can I get xml from xsd using simple tools?

Still need help with Gentoo, and your question doesn't fit in the above forums? Here is your last bastion of hope.
Post Reply
Advanced search
3 posts • Page 1 of 1
Author
Message
i92guboj
Bodhisattva
Bodhisattva
User avatar
Posts: 10315
Joined: Tue Nov 30, 2004 8:17 pm
Location: Córdoba (Spain)

Can I get xml from xsd using simple tools?

  • Quote

Post by i92guboj » Thu May 28, 2015 6:55 pm

Hello.

I am dumb when it comes to xml but the enterprise I am working for now is joining Amazon, and they seem to want some kind of xml jungle as the feed for the products. They provide some xsd files which are supposed to describe how the xml files are structured though I am having a bit of difficulty getting the hang of it. I never liked xml, but that's for another thread...

These xsd file include other xsd files, so the thing gets rather complex.

I have been reading lots of documents (from Amazon, and about XML, DTDs and XSDs in general). However, all they forget to mention how these relate at all in practice. I am trying to get a correct xml file from the Amazon-provided XSD files, but all I can find is related to either Eclipse or Netbeans or online converters (which of course do not work unless it's a trivial case).

So, my question is, do you know of any standard tool which can generate a correct xml file from an xsd so that I can use it as a template?

If not, can you tell me why the hell do I need an xsd at all if I will be writing all the grammar and stuff myself anyway?

General tips on how to handle this kind of stuff will also be welcome.

Thanks beforehand for any idea.
Top
miket
Guru
Guru
Posts: 513
Joined: Sat Apr 28, 2007 2:45 am
Location: Gainesville, FL, USA

  • Quote

Post by miket » Sat May 30, 2015 12:47 am

Just to be clear: XSD is the file type (and .xsd is the extension) for documents of W3C XML Schema, a validation framework for XML documents. An XML-Schema file states the grammar of an XML application. Think of it as the .yy file used by YACC/Bison to generate an LALR parser. You use it to test whether a document is legal, but not to generate random documents that conform to the grammar.

I sure hope they gave you some documentation for this XML application beyond the mere series of XSD files. For making a sample XML file you're on our own. Start with whatever the root tag is for this document and through trial and error extend this document and periodically run your validator over it:

Code: Select all

  xmllint --schema base_schema.xsd main_doc.xml
(The xmllint binary is almost certainly installed on your system; if it's not, emerge dev-libs/libxml2.)

Since XSD is for validating documents rather then generating them, there's no tool to create an empty template from it. The closest thing I know of to be able to do anything of the sort is the XMLMind editor.

The XMLMind editor could turn out to be useful be useful to you, but it's probably more likely instead to be a trip down the rabbit hole. Still, you might want to grab the evaluation version of it and get a bit of a feel for the XML-making process it supports. It's a commercial XML editor that lets you add only legal elements to your document so that it always follows the schema. It comes bundled with schemata for applications like DITA and DocBook and lets you set up your own custom schemata using an XML Schema. Once you had it set up, you could generate valid documents for the Amazon XML application. It is nice and easy to use (I tried it out years ago).

The downsides: setting up that configuration with the XML schema is tricky, the editor is a commercial product, and the evaluation version might not let you set up custom configurations. You ought to be aware of this package, though you, like me, may choose not to use it.


Now why validate, you ask? Having the validator can turn out to be quite handy. XML documents that get big might go wrong somewhere and by having things misnamed the application consuming the XML file might misbehave in subtle ways. (This is a reason why using XML files for system configuration is a bad choice.) I have written RelaxNG files for XML applications I've designed; it helps make sure that things are going the right way (RelaxNG is a different validator framework; I prefer it to XML Schema).


You mentioned making your own grammar. Is this really what you are doing, or are you simply creating documents that match what Amazon has given you? Perhaps you're extending the Amazon schema to do what you need. If you're doing ambitious things like that, I would advise making adjustments to that XSD framework.

Just to know, the lingo around XML uses the word schema to describe what you'd call a grammar if you were speaking of a programming language. The basic construction of XML is quite fixed: elements, attributes, CDATA, namespaces, entities, and all that. The schema has to do with the rules for assembling these fixed components. You don't get to make up your own markup.

As an example, look at this bit of XHTML:

Code: Select all

<div class="top">
   <a href="that_page.html">Go there</a>
</div>
The standard for XHTML requires, among other things, that the <a> element have an href attribute and/or a name attribute and may take character data (CDATA) as content, but would not allow, say, a cellspacing attribute to be present. A schema for XHTML (whether written in XML Schema or RelaxNG) would express all these things and would cause a validator like xmllint enforce them.
Top
i92guboj
Bodhisattva
Bodhisattva
User avatar
Posts: 10315
Joined: Tue Nov 30, 2004 8:17 pm
Location: Córdoba (Spain)

  • Quote

Post by i92guboj » Sat May 30, 2015 6:13 am

First, thanks for the detailed post. It's been quite helpful. If you get to detect a bit of sarcasm in my words below, note that it's all aimed at Amazon and their xsd stuff :lol:
miket wrote: I sure hope they gave you some documentation for this XML application beyond the mere series of XSD files.
Yes, they gave me some documentation... 80 wonderful pages that tell me how wonderful XML is and how it will solve all my problems. Oh, and with all the xsd pasted in the middle.

Useless as a drunken cow. A waste of time and manpower, if you ask me.
For making a sample XML file you're on our own.
That I feared. That's quite nice once you start reading "include" sentences in the root xsd file.
Since XSD is for validating documents rather then generating them, there's no tool to create an empty template from it. The closest thing I know of to be able to do anything of the sort is the XMLMind editor.
Thanks. Well, I get that part. What I don't see is how xsd are helpful at all. An empty xml would do the same, and would save quite a lot of work, again, thinking about the thirty includes in that damn Product.xsd file... oh, well...
The XMLMind editor could turn out to be useful be useful to you, but it's probably more likely instead to be a trip down the rabbit hole. Still, you might want to grab the evaluation version of it and get a bit of a feel for the XML-making process it supports. It's a commercial XML editor that lets you add only legal elements to your document so that it always follows the schema. It comes bundled with schemata for applications like DITA and DocBook and lets you set up your own custom schemata using an XML Schema. Once you had it set up, you could generate valid documents for the Amazon XML application. It is nice and easy to use (I tried it out years ago).

The downsides: setting up that configuration with the XML schema is tricky, the editor is a commercial product, and the evaluation version might not let you set up custom configurations. You ought to be aware of this package, though you, like me, may choose not to use it.
I don't think I will end using it. But it's certainly a good thing to know of its existence, just in case. Now that I am in deals with the devil I might very well just make it worth it and enjoy some sex/drugs/rockandroll and buy proprietary software while I am at it. :twisted:
Now why validate, you ask? Having the validator can turn out to be quite handy. XML documents that get big might go wrong somewhere and by having things misnamed the application consuming the XML file might misbehave in subtle ways. (This is a reason why using XML files for system configuration is a bad choice.) I have written RelaxNG files for XML applications I've designed; it helps make sure that things are going the right way (RelaxNG is a different validator framework; I prefer it to XML Schema).
You are probably right. I am biased against xml. I have used it now and then to generate documentation and html, but it's a pain in the ass to me. I never felt comfortable with it, and now I am hating it. I really can't make any sense of converting db to xml, wrapping it into a lot of idiotic tags and then converting that back to db again. I see a problem in that... Is like "buy a car, break it, fix it so it's the original car again". But hey, maybe it's just me...

There's not much I can do about it though, just rant here (which is always better and less disruptive than ranting in front of my boss at the office) and then do the damn idiotic thing and try to automate and forget about it until it breaks in four or five years. Hopefully I won't be there to fix it by then :lol: :wink: :twisted:
You mentioned making your own grammar. Is this really what you are doing, or are you simply creating documents that match what Amazon has given you?
Oh, no, nothing that ambitious hehe. I was talking in generic. The "grammar" (erm, "schema") is the one Amazon supplied. That's more than enough. They offered the alternative or tab separated text files, but I am trying to prevent greater pains in the future.

Thanks so much in any case, your post has been enlightening in many ways. :D
Top
Post Reply

3 posts • Page 1 of 1

Return to “Other Things Gentoo”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic