-1

I am working on trying to understand more about DTD and XML, and i have come across an issue. In fact, I have understood the syntax of DTD and XML but i am working on visual studio code and i wasn't able to execute the code.

How can i execute de code in order to see only the text for example: With the code in the picture Here, i would like to get:

Tove Jani Reminder Don't forget me this weekend !

However i haven't found any ways to execute this code. Thank you for your help !

George Fs
  • 7
  • 3
  • 1
    Please include code as text in a [`code` section](https://stackoverflow.com/help/formatting) and not as image. – zx485 Oct 04 '19 at 16:27
  • 2
    Can you explain please what you mean by "execute" and what you expect the output to be? XML isn't code, it's [markup language](https://en.wikipedia.org/wiki/Markup_language). It doesn't in itself have a notion of being *executed* because it isn't in itself instructions. However many different tools and applications can use it as an input in order to control some functionality. If you intend that, could you please specify in your question? – Tom W Oct 04 '19 at 16:39

1 Answers1

0

You can use a tool like xmlstarlet to validate an XML against a DTD.
Here is a sample from the xmlstarlet help:

Usage: xmlstarlet val <options> [ <xml-file-or-uri> ... ]
where <options>
  -w or --well-formed        - validate well-formedness only (default)
  -d or --dtd <dtd-file>     - validate against DTD
  --net                      - allow network access
  -s or --xsd <xsd-file>     - validate against XSD schema
  -E or --embed              - validate using embedded DTD
...

In your case the appropriate command could look like this:

xmlstarlet val -d note.dtd note.xml

To get the string value

Tove Jani Reminder Don't forget me this weekend !

you have to use XPath. An XPath-1.0 expression in your case could be:

normalize-space(/note)

Then pass this XPath-1.0 expression to, for example, xmlstarlet like

xmlstarlet sel -t -v 'normalize-space(/note)' note.xml

to get desired result.
Of course you can use other tools; xmlstarlet was just an example.

zx485
  • 28,498
  • 28
  • 50
  • 59