Customize docbook the preferred way - extend

I'd like to add a few elements to docbook 5 and to change a few elements. The question is: what is the preferred way?
My root element looks like this:
<book xmlns="http://docbook.org/ns/docbook" version="5.0">
</book>
And I guess I should change it to
<book xmlns="http://docbook.org/ns/docbook" version="5.0-extension acme-1.0">
</book>
Or something like this. Should I change the namespace as well? I believe I should, but this gives me some trouble, as the RelaxNG grammar expects the namespace to be http://docbook.org/ns/docbook and not for example http://example.org/ns/docbook-myextension.
My .rng file looks like this:
<grammar xmlns:db="http://docbook.org/ns/docbook" xmlns="http://relaxng.org/ns/structure/1.0">
<include href="docbookxi.rng">
<!-- change things here -->
</include>
<!-- add things here -->
</grammar>

Related

How can I have named entities in asciidoctor?

I'm using asciidoctor with the docbook backend for books. In the past I wrote DocBook, which allows me to declare named entities that I use throughout the book:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE book [
<!ENTITY class "Galactic TOP SECRET">
<!ENTITY project "World Domination">
<!ENTITY product "Illuminati Mind Control Chemtrail Spray System CSS-2020">
]>
<book ...>
...
What about our &class; &project;?
Is our &product; working?
...
</book>
:-)
I haven't found a way to tell asciidoctor to insert the DOCTYPE declaration between the XML processing instruction and the <book> element. So I resorted to --no-header-footer and prepending the header and footer lines. Is there a better way to do this? Something like a named entity definition directive? An include mechanism?
Do you have to use Docbook entity declarations? Asciidoctor has "attributes" that can serve the same purpose: https://asciidoctor.org/docs/user-manual/#attributes
For example, you can define an attribute within your document:
:class: Galactic TOP SECRET
Then later in your document, you can use the attribute:
"Billy, come up to the front and address the {class}." said the teacher.
When you transform your document to Docbook, you would see:
<simpara>"Billy, come up to the front and address the Galactic TOP SECRET."
said the teacher.</simpara>
If you do have to use Docbook entity declarations, you might use some XSL to transform the XML you get into the XML you want.

CA1703 CodeAnalysis Error and CasingExceptions

I have a text resource "{0} by Test GmbH" which is correctly spelled because GmbH is the official Abbreviation for "Gesellschaft mit beschränkter Haftung". I understand that Microsoft CodeAnalysing tries to tokenize it into "Gmb" and "H" however I think it should be possible to introduce this term as known with that specific spelling and casing with this CodeAnalysingDictionary:
<?xml version="1.0" encoding="utf-8" ?>
<Dictionary>
<Words>
<Unrecognized>
</Unrecognized>
<Recognized>
<Word>Gmbh</Word>
</Recognized>
<Deprecated>
</Deprecated>
<DiscreteExceptions>
<Term>GmbH</Term>
</DiscreteExceptions>
</Words>
<Acronyms>
<CasingExceptions>
<Acronym>GmbH</Acronym>
</CasingExceptions>
</Acronyms>
</Dictionary>
However it does not work out:
CA1703 Resource strings should be spelled correctly
In resource 'MyCode.Properties.Resources.resx',
referenced by name 'CopyrightWithCompanyName',
correct the spelling of 'Gmb' in string value '{0} by Test GmbH'.
How can I adjust the dictionary correctly?
Actually, provided that GmbH should be interpreted as a compound word that consists of the words Gmb and H, the casing of GmbH is correct.
So, in order for GmbH to be seen as valid by Code Analysis and thereby eliminate CA1703, simply add gmb as a recognized word to your custom dictionary file:
<Dictionary>
<Words>
<Recognized>
<Word>gmb</Word>
<!-- ... -->
</Recognized>
<!-- ... -->
</Words>
<!-- ... -->
</Dictionary>
I confirmed that this works in Visual Studio 2013.
According to http://msdn.microsoft.com/en-us/library/bb514188.aspx#bkmk_dictionaryacronymscasingexceptionsacronym
entries in the CasingExceptions are only applied to CA1709: Identifiers should be cased correctly, not to resources.
I have the exact same problem but no solution other then suppress the warning

How to Extract Text Node Value From Payload Using XPath in MEL

I want to extract some text values from an message's XML payload so that I can use them in a jdbc query.
Given the test XML file below I want to obtain the string value of first book's author text node.
Something like:
INSERT INTO books VALUES (#[xpath('/catalog/book[0]/author/text()')])
To test the expression I am just using a logger but can't seem to get it to extract correctly.
<logger message="#[xpath('/catalog/book[0]/author/text()')]" level="DEBUG" doc:name="Logger"/>
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
</book>
</catalog>
Here is the correct MEL expression:
#[xpath('/catalog/book[1]/author/text()').text]
Note in XPath, the first node is 1 not 0.
David's answer worked fine except for one thing. For me, .text didn't work. I had to use .wholeText. This is probably because I'm using a xerces implementation somewhere in my work project.

Docbook publishing for different target audiences

I like to have one docbook xml document that has content for several target audiences. Is there a filter that enables me to filter out the stuff only needed for "advanced" users?
The level attribute is invented by me to express what I have in mind.
<?xml version="1.0"?>
<book>
<title lang="en">Documentation</title>
<chapter id="introduction" level="advanced">
<title>Introduction for advanced users</title>
</chapter>
<chapter id="introduction" level="basic">
<title>Introduction for basic users</title>
</chapter>
<chapter id="ch1">
<para level="basic">Just press the button</para>
<para level="advanced">
Go to preferences to set your
needs and then start the process
by pressing the button.
</para>
</chapter>
</book>
DocBook does not have a level attribute. Perhaps you meant userlevel?
If you are using the DocBook XSL stylesheets to transform your documents, they have built-in support for profiling (conditional text). To use it you need to
use the profiling-enabled version of the stylesheet (e.g. use html/profile-docbook.xsl instead of the usual html/docbook.xsl), and
specify the attribute values you want to profile on via a parameter (e.g. set profile.userlevel to basic).
Chapter 26 of Bob Stayton's DocBook XSL: The Complete Guide has all the details.
Two ways, off the top of my head:
Write a quick script that takes the level as a parameter and, using XPath or regular expressions, that only spits out the XML you want.
Write an XSLT transformation that will spit out the XML you want.
(2) is cleaner, but (1) is probably faster to write up.

MSBuild XMLUpdate Question

I am using the XMLUpdate to update an xml formatted file in MSBuild. It updates fine but adds <?xml version="1.0" encoding="utf-8"?> at the top after update. Here is my statement that updates
<Import Project="C:\Program Files\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<XmlUpdate XmlFileName="$(AppName).alx" Xpath="/loader/application/version" Value="$(AppVersion)" />
Is it possible to update without the xml element at the top?
Thanks
Ponnu
The <?xml ...> is more of a descriptor than a real XML element. It describes your document and, for example defines the encoding. It won't interfere with your existing elements. I think it is even a standard feature of a XML document (but I don't have the specs handy)