我有一个XML Schema,其中包含使用<xs:union>和的数据类型<xs:list>.这是一个摘录:
<xs:simpleType name="mixeduniontype">
<xs:union memberTypes="xs:boolean xs:int xs:double xs:string"/>
</xs:simpleType>
<xs:simpleType name="valuelist">
<xs:list itemType="xs:double"/>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)
这是一个示例XML片段:
<value>42</value>
<value>hello</value>
<values>1 2 3.2 5.6</values>
Run Code Online (Sandbox Code Playgroud)
两个上部<value>元素是联合,下部<values>元素是列表.
我的问题是,我如何解析.NET中的元素<xs:union>和<xs:list>元素?
如何检查union元素中的值具有哪种数据类型?
如何提取列表元素中的元素并将其转换为C#列表?
System.XML中是否有内置的支持用于这种解析,或者我是否需要自己编写解析代码?
以下是我在为SOAP服务生成客户端时尝试使用的xsd,Eclipse正在抛出错误:元素"xs:schema"的前缀"xs"未绑定.
<xs:schema version="1.0"
targetNamespace="bdo.com.ph/RemitAPI">
<xs:element name="CheckServiceResponse"
nillable="true" type="xs:string"/>
<xs:element name="apiRequest" nillable="true" type="tns:APIRequest"/>
.............................
<xs:element name="referenceNo" type="xs:string" form="qualified"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
我从webservice获得了这个xsd
<?xml version="1.0" encoding="utf-8"?>
<transaction>
<itemset id="1">
<item>pen</item>
<item>notebook</item>
<item>pencile box</item>
</itemset>
<itemset id="2">
<item>pen</item>
<item>notebook</item>
<item>pencile box</item>
<item>ink</item>
</itemset>
<itemset id="3">
<item>ink</item>
<item>milk</item>
</itemset>
<itemset id="4">
<item>pen</item>
<item>notebook</item>
<item>pencile box</item>
<item>ink</item>
<item>milk</item>
<item>paper</item>
</itemset>
<itemset id="5">
<item>pen</item>
<item>ink</item>
<item>notebook</item>
</itemset>
</transaction>
Run Code Online (Sandbox Code Playgroud)
我是XQuery的新手.我正在使用BaseX来运行XQuery.我的目标是根据每个交易中非常流行的Apriori算法找到1-频繁的2频率项目集... n频繁项目集,并想要计算它们.
我已经完成了找到1个频繁的项目集及其支持计数.但我无法使用XQuery找到2项集及其支持计数.有人可以帮我这么做吗?这是我试过的代码......
let $src:= doc('XML/test.xml')/transaction/itemset
let $minsup:= 3
let $C:=distinct-values($src/*)
let $l:=for $itemset in $C
let $items:=(for $item in $src/*
where $itemset=$item
return $item)
let $sup := count($items)
where $sup>=$minsup
order by $sup descending
return<itemset>
<item> {$itemset} </item> …Run Code Online (Sandbox Code Playgroud) 我有一个我无法改变的现有命名空间.我需要将元素添加到复杂类型,以便生成的XML如下所示:
原始XML:
<?xml version="1.0"?>
<Book xmlns="http://bookshop.com">
<Author>Frank Herbert</Author>
<Title>Dune</Title>
</Book>
Run Code Online (Sandbox Code Playgroud)
新XML:
<?xml version="1.0"?>
<Book xmlns="http://bookshop.com"
xlmns:custom="http://custombookshop.com>
<Author>Frank Herbert</Author>
<Title>Dune</Title>
<custom:Publisher>Ace</custom:Publisher>
</Book>
Run Code Online (Sandbox Code Playgroud)
我要求自定义元素必须如上所示显示名称空间前缀,并且复杂类型名称不得更改.
这是原始的XSD和我尝试使用重新定义的新XSD.这会有效,还是有更好的方法来实现这一目标?提前感谢您的建议.
原XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://bookshop.com"
targetNamespace="bookshop.com">
<xs:complexType name="Book">
<xs:complexContent>
<xs:sequence>
<xs:element name="Author" type="String32"
minOccurs="1" maxOccurs="1" />
<xs:element name="Title" type="String32"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
我尝试过新的XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://custombookshop.com"
targetNamespace="custombookshop.com">
<xs:redefine schemaLocation="http://bookshop.com">
<xs:complexType name="Book">
<xs:complexContent>
<xs:extension base="Book">
<xs:sequence>
<xs:element name="Publisher" type="String32"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
</xs:schema>
Run Code Online (Sandbox Code Playgroud) 我是XML Schema的新手,我遇到的架构文档将许多前缀绑定到xsd:schema根元素中的各个命名空间,并且还导入了这些模式的子集.在XML Schema文档的其余部分中,他们很乐意使用xsd:schema元素中绑定的所有前缀(无论是否导入).
那么import命名空间的含义是什么意味着"只是"将该命名空间绑定到前缀?
从我阅读的Definitive XML Schema书中可以看到(第66页):
导入用于告诉处理器您将引用其他命名空间中的组件
在我的理解中,这也是一个绑定所做的,那么有什么区别?
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vr="http://www.ivoa.net/xml/VOResource/v1.0"
xmlns:ssap="http://www.ivoa.net/xml/SSA/v1.0"
xmlns:vm="http://www.ivoa.net/xml/VOMetadata/v0.1"
targetNamespace="http://www.ivoa.net/xml/SSA/v1.0"
elementFormDefault="unqualified"
attributeFormDefault="unqualified"
version="1.0pr2">
<xs:import namespace="http://www.ivoa.net/xml/VOResource/v1.0"
schemaLocation="http://www.ivoa.net/xml/VOResource/v1.0"/>
<!-- ... rest of the schema document follows -->
Run Code Online (Sandbox Code Playgroud)
http://www.ivoa.net/xml/VOResource/v1.0上述模式文档中的命名空间都绑定到vr前缀并导入.其他名称空间仅绑定到某些前缀而不导入.文档的其余部分使用来自vr(绑定和导入)和ssa(绑定但未导入)前缀的组件.有什么不同?
我想使用 translate 函数而不是使用 replace 从字符串中删除单词 '和' 。
例如:
<xsl:variable name="nme" select="translate(./Name/text(), ',:, '')" />
Run Code Online (Sandbox Code Playgroud)
除了“,:”,我还想删除“和”这个词。请建议。
在Alloy book的4.7.2节的下面的代码中,this关键字引用了什么?
module library/list [t]
sig List {}
sig NonEmptyList extends List {next: List, element: t}
Run Code Online (Sandbox Code Playgroud)
...
fun List.first : t {this.element}
fun List.rest : List {this.next}
fun List.addFront (e: t): List {
{p: List | p.next = this and p.element = e}
}
Run Code Online (Sandbox Code Playgroud)
如果您在Alloy中详细说明这种用法,我将不胜感激.
我试图解析一个非常简单的例子:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/'>
<openSearch:totalResults>100</openSearch:totalResults>
</root>
Run Code Online (Sandbox Code Playgroud)
我使用的样式表如下:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:app='http://www.w3.org/2007/app' >
<xsl:output method="xml" indent="yes"/>
<xsl:preserve-space elements="*"/>
<xsl:template match="/">
<results>
<xsl:attribute name="total-results">
<xsl:value-of
select="atom:root/openSearch:totalResults"/>
</xsl:attribute>
</results>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
这在libxslt中工作,没问题.我现在尝试在java中执行相同的任务,我正在尝试使用javax.xml.transform包来执行此操作.它不是预期的结果,而是为total-results属性提供一个空值.但是,当我将值更改为:
<xsl:value-of select="root/totalResults"/>
Run Code Online (Sandbox Code Playgroud)
有用.更改xml和xslt不是一个选项.我应该在某个地方设置一个参数吗?代码非常简单:
InputSource xmlSource = new InputSource( new StringReader(xml) );
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(xmlSource);
// Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource stylesource = new StreamSource(new StringReader(styleSheet));
Transformer transformer = tFactory.newTransformer(stylesource);
StringWriter writer = new StringWriter();
DOMSource source = …Run Code Online (Sandbox Code Playgroud) 如何获得for-each循环中所有项目的总成本?
<?xml version="1.0" encoding="utf-8" ?>
<Characters>
<Character ID="1" Name="Simmo">
<Inventory MaxSlots="20">
<Item ID="1" Name="Gold" Cost="1">
<Count>100</Count>
</Item>
<Item ID="1" Name="hat" Cost="10">
<Count>1</Count>
</Item>
<Item ID="2" Name="stick" Cost="15">
<Count>2</Count>
</Item>
</Inventory>
</Character>
</Characters>
Run Code Online (Sandbox Code Playgroud)
例如1*100 + 10*1 + 15*2 = 140
我未完成的 xsl解决方案:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>xsl file</title>
</head>
<body>
<ul>
<xsl:for-each select="/Characters/Character">
<li>
Character name: <xsl:value-of select="@Name"/>
<br/>
<xsl:for-each select="Inventory/Item">
<xsl:variable name="cos" select="@Cost"/>
<xsl:variable name="cou" select="Count"/>
<xsl:variable …Run Code Online (Sandbox Code Playgroud) 我有一个 XML,需要为其生成 XSD。我的 XML 如下:
实例:
<mes:GetInboundResponseGetInboundSMS
xmlns:mes="http://abcd.com">
<response>
<messages>
<item>
<date>15/04/2014 00:00:00</date>
</item>
<item>
<date>01/07/2014 10:01:32</date>
</item>
</messages>
</response>
</mes:GetInboundResponseGetInboundSMS>
Run Code Online (Sandbox Code Playgroud)
请注意,只有最外面的元素GetInboundResponseGetInboundSMS属于命名空间http://abcd.com- 其余元素不属于。如何在 XSD 中指定这一点?
我尝试过以下 XSD,但这给了我错误:
XSD:
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="GetInboundResponseGetInboundSMS">
<xs:complexType>
<xs:sequence>
<xs:element name="response">
<xs:complexType>
<xs:sequence>
<xs:element name="messages">
<xs:complexType>
<xs:sequence>
<xs:element name="item"
maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用在线验证器通过 XSD 验证实例时,我最终遇到了以下错误:
无效。
错误 - 第 1 行,第 95 …