0

我无法哄骗hxt包构建正确表示默认 XML属性的 DTD 。

我的pickler中包含的 DTD错误地要求为已定义默认值的属性提供显式值。Pickler在解析未验证的输入时正确应用默认值,但在根据 DTD 验证输入时失败,这需要显式的属性值。

作为使用ghci的示例,我为属性创建一个pickler并定义一个默认值,然后提取 DTD,它指定一个值是REQUIRED。如果定义了默认值 TWICE,那么奇怪的是 DTD 定义了该值是IMPLIED。如果将值定义为元素而不是属性,则 DTD 将值量化为 ' ? ',表明它是可选的;更好,但我想要一个属性

Prelude> :m + Text.XML.HXT.Core
Prelude Text.XML.HXT.Core> _ <- runX $ constA undefined >>> xpickleWriteDTD (xpElem "root" . xpDefault 0 $ xpAttr "attr" xpInt) [] "-" --There's probably an easier way of achieving this.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [
<!ELEMENT root EMPTY >
<!ATTLIST root attr CDATA #REQUIRED >
]>
Prelude Text.XML.HXT.Core> _ <- runX $ constA undefined >>> xpickleWriteDTD (xpElem "root" . xpDefault 0 . xpAttr "attr" $ xpDefault undefined xpInt) [] "-"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [
<!ELEMENT root EMPTY >
<!ATTLIST root attr CDATA #IMPLIED >
]>
Prelude Text.XML.HXT.Core> _ <- runX $ constA undefined >>> xpickleWriteDTD (xpElem "root" . xpDefault 0 $ xpElem "elem" xpInt) [] "-"
<?xml version="1.0" encoding="UTF-8"?>                                                                                                                                                
<!DOCTYPE root [                                                                                                                                                                      
<!ELEMENT elem (#PCDATA) >                                                                                                                                                            
<!ELEMENT root (elem)? >                                                                                                                                                              
]>                                       
4

1 回答 1

1

I have received a response from the author of this package, which clarifies the issue;

I suspect, with the current version of HXT it's not possible do describe default values for attributes within the pickler module. The feature of deriving a DTD out of the picklers is somewhat experimental and we have not implemented every corner case available in DTDs. In the datatype used in the picklers for schema info (DTD or other schemata) there's no field holding a default attribute value.

于 2013-05-31T12:29:24.153 回答