English 中文(简体)
这是一种有效的RELAXNG模式吗? I m 获取“Relax-NG 有效性错误:相互代谢中的无效顺序”
原标题:Is this a valid RELAX NG model? I m getting " Relax-NG validity error : Invalid sequence in interleave"

Well, I m trying to create a RELAX NG schema for PRTG advanced sensor output. Unfortunately the XML specification is a terrible mess IMHO, but I tried anyway.

Basically there are two possible results:

  • Success: There can be a Text element and there will be at least one Result element.
  • Error: There will be an Error element and (an optional?) Text element, too.

So my schema starts like this:

<?xml version="1.0" encoding="utf-8"?>
<!-- RELAX NG specification for PRTG Advanced Sensors -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         xmlns:a="http://relaxng.org/ns/annotation/1.0">
  <start>
    <element name="Prtg">
      <choice>
        <interleave><!-- error -->
          <element name="Error"><ref name="C.Boolean" /></element>
          <element name="Text"><ref name="DT.Message" /></element>
        </interleave>
        <interleave><!-- success -->
          <optional>
            <element name="Text"><ref name="DT.Message" /></element>
          </optional>
          <oneOrMore>
            <element name="Result">
              <interleave>
                <element name="Channel"><text /></element>
                <element name="Value"><text /></element>
                <ref name="PRTG-TagSoup" />
              </interleave>
            </element>
          </oneOrMore>
        </interleave>
      </choice>
    </element>
  </start>
  <!-- ... -->
</grammar>

C.Boolean is basically 0 or 1, and DT.Message is basically <text />. PRTG-TagSoup is a set of all-optional elements that excludes Text, Error, and Result.

I would say it s clear what is an error, and what is success, but xmllint seems to have trouble with that: I get error messages like this:

element Prtg: Relax-NG validity error : Expecting an element Error, got nothing
element Result: Relax-NG validity error : Invalid sequence in interleave
Relax-NG validity error : Extra element Text in interleave
element Prtg: Relax-NG validity error : Element Prtg failed to validate content

A sample input that triggers those messages is:

<?xml version="1.0" encoding="UTF-8"?>
<!--MonitoringOutput v0.2 id=id-16371 (PRTG.xsl v0.0.3)-->
<Prtg>
  <!--status_string=OK-->
  <!--Exit Code: 0-->
  <Text>OK</Text>
  <Result>
    <Channel>wr_wait</Channel>
    <Value>0.938023</Value>
    <!--range: min="0"-->
  </Result>
<!-- ... -->
  <Result>
    <Channel>rd_wait</Channel>
    <Value>0</Value>
    <!--range: min="0"-->
  </Result>
</Prtg>

Somehow my guess is that xmllint seeing the Text element does not know which branch to take. Even if I move the Text element after the last Result element, it does not parse.

Missing Parts

这里是失踪的那部分人,留待强调核心问题(正如我看到的那样):

  <define name="C.Boolean">
    <choice datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
      <value type="integer">0</value>
      <value type="integer">1</value>
    </choice>
  </define>

  <define name="DT.Message">
    <data datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
          type="string">
      <param name="pattern">".{0,2000}"</param>
    </data>
  </define>

  <define name="PRTG-TagSoup">
    <a:documentation>
      Unordered set of optional elements.
      The actual logic is hard to get from the specification.
    </a:documentation>
    <zeroOrMore>
      <choice>
        <!--- many more... -->
        <element name="CustomUnit"><text /></element>
        <element name="Float"><ref name="C.Boolean" /></element>
        <element name="Warning"><ref name="C.Boolean" /></element>
        <element name="ShowChart"><ref name="C.Boolean" /></element>
        <element name="ShowTable"><ref name="C.Boolean" /></element>
        <element name="LimitErrorMsg"><text /></element>
        <element name="LimitWarningMsg"><text /></element>
        <element name="LimitMode"><ref name="C.Boolean" /></element>
        <element name="ValueLookup"><text /></element>
        <element name="NotifyChanged"><empty /></element>
      </choice>
    </zeroOrMore>
  </define>
问题回答

<代码>中使用的定期表述有误。 DT.Message patterns.

Jing 有效者将以下错误信息输入你的XML文件和图谱:

prtg.xml:6:18:差错:要素“Text”的特性内容无效;必须是与正常表述“{0,2000}”相匹配的。

如果该表述从<代码>{0,2000}>改为.{0,2000},则该单证即予以确认(既有成文又有xllint)。





相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签