标签: xml-namespaces

使用带有包含的XSD

这是一个XSD:

<?xml version="1.0"?>
<xsd:schema 
elementFormDefault='unqualified' 
attributeFormDefault='unqualified' 
xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
>

  <xsd:simpleType name='TheSimpleType'>
    <xsd:restriction base='xsd:string' />
  </xsd:simpleType>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)

这是第二个包含上述XSD的XSD:

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema 
elementFormDefault='unqualified' 
attributeFormDefault='unqualified' 
xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
targetNamespace='a'
xmlns='a'
>

  <xsd:include schemaLocation='Include.xsd' />

  <xsd:element name = "TheElement" >
  <xsd:complexType>
  <xsd:attribute name="Code" type="TheSimpleType" use="required"/>
  </xsd:complexType>
  </xsd:element>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)

我需要将(第二个)XSD读入C#并且:

  1. 检查它是否是有效的XSD,并且
  2. 验证文件.

下面是一些要在schemata中读取的C#:

    XmlSchemaSet schemaSet = new XmlSchemaSet();
    foreach (string sd in Schemas)
    {
        using (XmlReader r = XmlReader.Create(new FileStream(sd, FileMode.Open)))
        {
            schemaSet.Add(XmlSchema.Read(r, null));
        }
    }
    schemaSet.CompilationSettings = new XmlSchemaCompilationSettings();
    schemaSet.Compile();
Run Code Online (Sandbox Code Playgroud)

.Compile()失败,因为"Type'a:TheSimpleType'未声明,或者不是简单类型."

但是,它适用于:

  • 命名空间将从架构中删除,或
  • 命名空间被添加到include中.

问题是:如何在不编辑架构的情况下让C#接受它? …

c# xml xsd xml-namespaces

17
推荐指数
2
解决办法
9218
查看次数

无法找到Spring NamespaceHandler错误

我已经有这个错误已经有将近一个星期了,我现在就准备好了.我已经使用Maven2制作了BIG jar文件.当我使用以下命令运行jar文件时:

 java -jar someJar.jar
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

 ERROR: [27/55/13 10:55] Launcher: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
 Offending resource: class path resource [JavaProjectApplicationContext.xml]
Run Code Online (Sandbox Code Playgroud)

JavaProjectApplicationContext.xml如下:

 <?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/jee
       http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"> 

<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>deployment.properties</value></property>
</bean>

<bean id="LexEditorDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"><value>${hibernate.jdbc_driver}</value></property>
<property name="username"><value>${hibernate.username}</value></property>
<property name="password"><value>${hibernate.password}</value></property>
<property name="url"><value>${hibernate.url}</value></property>
<property name="defaultAutoCommit"><value>${hibernate.default_auto_commit}</value>   </property>
<property name="maxActive"><value>20</value></property>
<property name="maxIdle"><value>3</value></property>
 <property name="testOnBorrow"><value>true</value></property>
<property name="testOnReturn"><value>true</value></property>
<property name="testWhileIdle"><value>true</value></property>
</bean>

 <context:component-scan base-package="com.k_int.bank.plugin">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/> …
Run Code Online (Sandbox Code Playgroud)

spring xml-namespaces

17
推荐指数
1
解决办法
2万
查看次数

在针对WSDL(xsd架构)验证xml时理解elementFormDefault限定/不合格

我试图理解elementFormDefault="qualified/unqualified"嵌入在WSDL(SOAP 1.1,WSDL 1)中的XML模式的含义.

例如,我在WSDL中有这个模式:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    targetNamespace="http://www.example.com/library">
    <xsd:element name="person">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="name" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)

在纯XML中,这显然是无效的,因为"name"没有指定的命名空间:

<lib:person xmlns:lib="http://www.example.com/library">
    <name>XML Schema</name>
</lib:person>
Run Code Online (Sandbox Code Playgroud)

虽然这显然是有效的,因为所有元素都是合格的:

<lib:person xmlns:lib="http://www.example.com/library">
    <lib:name>qualified xml</lib:name>
</lib:person>
Run Code Online (Sandbox Code Playgroud)

但令人惊讶的是libxml说以下内容也是有效的:

<person xmlns="http://www.example.com/library">
    <name>XML Schema</name>
</person>
Run Code Online (Sandbox Code Playgroud)

问题1:我认为qualified意思<person>应该是这个样子<lib:person xmlns:lib="...">.但结果似乎表明该xmlns属性是一样的?

现在假设上面的XML是SOAP请求的一部分,例如

...
<s:Body>
    <person xmlns="http://www.example.com/library">
        <name>XML Schema</name>
    </person>
</s:Body>
...
Run Code Online (Sandbox Code Playgroud)

问题2:如果WSDL包含qualified上面显示的模式,请求上面的请求是否有效?(普通SOAP,无视WS-I基本配置文件)

问题3当我考虑WS-I Basic配置文件(特别是4.1.13 SOAP Body和Namespaces)时上述请求是否仍然有效?(被person认为是"命名空间合格"?)

xml xsd soap wsdl xml-namespaces

17
推荐指数
1
解决办法
2万
查看次数

XSL - 如何从源xml中删除未使用的命名空间?

我有一个带有许多未使用的命名空间的xml,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<ns1:Envelope xmlns:ns1="http://www.a.com" xmlns:ns2="http://www.b.com" xmlns:ns3="http://www.c.com" xmlns:ns4="http://www.d.com">
    <ns1:Body>
        <ns2:a>
            <ns2:b>data1</ns2:b>
            <ns2:c>data2</ns2:c>
        </ns2:a>
    </ns1:Body>
</ns1:Envelope> 
Run Code Online (Sandbox Code Playgroud)

我想删除未使用的命名空间,而不必在xslt中指定要删除/维护的名称空间.结果xml应该是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<ns1:Envelope xmlns:ns1="http://www.a.com" xmlns:ns2="http://www.b.com">
    <ns1:Body>
        <ns2:a>
            <ns2:b>data1</ns2:b>
            <ns2:c>data2</ns2:c>
        </ns2:a>
    </ns1:Body>
</ns1:Envelope> 
Run Code Online (Sandbox Code Playgroud)

我已经google了很多,但还没有找到解决这个问题的方法.有没有?

谢谢.

PS:不是100%肯定,但我认为应该是XSL 1.0.

xml xslt xml-namespaces

16
推荐指数
1
解决办法
9746
查看次数

解析MSXML时引用未声明的命名空间前缀

我该如何解决

Reference to undeclared namespace prefix: '%s'
Run Code Online (Sandbox Code Playgroud)

微软的msxml实现问题?


我正在使用来自政府网站的XML Feed,其中包含我需要解析的值.xml包含名称空间:

<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://purl.org/rss/1.0/"
    xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:dcterms="http://purl.org/dc/terms/"
    xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3c.org/1999/02/22-rdf-syntax-ns#rdf.xsd">
    <item rdf:about="http://www.bankofcanada.ca/stats/rates_rss/STATIC_IEXE0101.xml">
        <cb:statistics>
            <cb:exchangeRate>
                <cb:value decimals="4">1.0351</cb:value>
                <cb:baseCurrency>CAD</cb:baseCurrency>
                <cb:targetCurrency>USD</cb:targetCurrency>
                <cb:rateType>Bank of Canada noon rate</cb:rateType>
                <cb:observationPeriod frequency="daily">2011-05-09T12:15:00-04:00</cb:observationPeriod>
            </cb:exchangeRate>
        </cb:statistics>
    </item>
</rdf:RDF>
Run Code Online (Sandbox Code Playgroud)

运行XPath查询:

/rdf:RDF/item/cb:statistics/cb:exchangeRate/cb:targetCurrency
Run Code Online (Sandbox Code Playgroud)

失败并出现错误:

Reference to undeclared namespace prefix: 'rdf'
Run Code Online (Sandbox Code Playgroud)

编辑:

如果我编辑原始XML以删除所有命名空间的使用:

<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf>
    <item>
        <statistics>
            <exchangeRate>
                <value decimals="4">1.0351</value>
                <baseCurrency>CAD</baseCurrency>
                <targetCurrency>USD</targetCurrency>
                <rateType>Bank of Canada noon rate</rateType>
                <observationPeriod frequency="daily">2011-05-09T12:15:00-04:00</observationPeriod>
            </exchangeRate>
        </statistics>
    </item>
</rdf>
Run Code Online (Sandbox Code Playgroud)

查询/rdf/item/statistics/exchangeRate/baseCurrency不会失败,并返回节点:

<baseCurrency>CAD</baseCurrency>
Run Code Online (Sandbox Code Playgroud)

如何让Microsoft XML与名称空间一起使用? …

msxml xml-namespaces msxml6

16
推荐指数
1
解决办法
3万
查看次数

Java:编组对象 - 在xml中删除额外的ns2注释

我试图根据定义的模式将对象中的数据编组到xml文件中.但是,当我打印出xml文件时,我在xml标签上收到了额外的注释.有没有办法摆脱额外的命名空间注释(即ns2)

这是我从编组中收到的xml的一个例子.

<?xml version="1.0" encoding="UTF-8" standalone="yes">
<root xmlns:ns2="http://www.something.com/something">
    <ns2:food>steak</ns2:food>
    <ns2:beverage>water</ns2:beverage>
</root>
Run Code Online (Sandbox Code Playgroud)

我想要的是这样的:

<?xml version="1.0" encoding="UTF-8" standalone="yes">
<root xmlns="http://www.something.com/something">
    <food>steak</food>
    <beverage>water</beverage>
</root>
Run Code Online (Sandbox Code Playgroud)

这就是我的Java代码正在做的事情:

            JAXBContext context = JAXBContext.newInstance("com.schema");
            JAXBElement<FoodSchema> element = new JAXBElement<FoodSchema>
                (new QName("FoodSchema"), Food.class, foodSchema);
            Marshaller marshaller = context.createMarshaller();
            OutputStream os = new FileOutputStream(object.getFilePath());
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 
            marshaller.marshal(element, os);
Run Code Online (Sandbox Code Playgroud)

任何帮助深表感谢!谢谢!

java xml jaxb marshalling xml-namespaces

16
推荐指数
2
解决办法
3万
查看次数

XML命名空间如何工作

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.1.xsd">

  <context:component-scan
      base-package="com.springinaction.chapter01.knight" />

</beans>
Run Code Online (Sandbox Code Playgroud)

上面的示例显示了具有多个名称空间的XML文件的示例.这些命名空间的目的是什么,最重要的是,即使没有Internet连接,它们也能正常工作?

我认为第二位开头xsi:schemaLocation包含XML模式文件,用于验证XML文档的结构.如果我在不在网络上的计算机上运行使用此配置文件的应用程序,为什么这些仍然有效?URL是否以某种方式别名为JAR文件?

java xml spring xsd xml-namespaces

16
推荐指数
2
解决办法
4830
查看次数

XML命名空间URI的良好或通用命名约定

我正在寻找一些关于xsd目标命名空间的良好命名约定的想法.

基本上我只需要明确决定如何命名我的xsd的目标命名空间,所以我试着在第一次就把它弄好.稍后更改它将需要更改另一个不受我控制的系统.

您是否有过任何优秀且有效的解决方案的XML架构创建经验?我试图在线查找信息,但大多数示例只使用非常通用的目标命名空间,如"http:// exampleSchema"等.我实际上是想找到一些现实生活中的例子.

xml xsd naming-conventions xml-namespaces

15
推荐指数
1
解决办法
6534
查看次数

Python:忽略elementtree.ElementTree中的xmlns

有没有办法忽略tage名称中的XML命名空间elementtree.ElementTree

我尝试打印所有technicalContact标签:

for item in root.getiterator(tag='{http://www.example.com}technicalContact'):
        print item.tag, item.text
Run Code Online (Sandbox Code Playgroud)

我得到类似的东西:

{http://www.example.com}technicalContact blah@example.com
Run Code Online (Sandbox Code Playgroud)

但我真正想要的是:

technicalContact blah@example.com
Run Code Online (Sandbox Code Playgroud)

有没有办法只显示后缀(sans xmlns),或更好 - 迭代元素而不明确说明xmlns?

python xml elementtree xml-namespaces

15
推荐指数
1
解决办法
7289
查看次数

自动创建的用于xml反序列化的C#类不起作用

我正在努力为这个xml创建反序列化类:

<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:stn="urn:response">
    <SOAP-ENV:Body>
        <Response>
            <Records xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="stn:Record[1]">
                <item xsi:type="stn:Record">
                    <person xsi:type="xsd:string">John Johnos</person>
                    <address xsi:type="xsd:string">Some Street 1</address>
                    <age xsi:type="xsd:string">24</age>
                </item>
            </Records>
            <status xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="stn:status[1]">
                <item xsi:type="stn:status">
                    <status xsi:type="xsd:string">success</status>
                    <message xsi:type="xsd:string"/>
                </item>
            </status>
        </Response>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)

我试图使用自动创建的代码(在VisualStudio 12中:编辑 - >选择性粘贴 - >将XML粘贴为类):

/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://schemas.xmlsoap.org/soap/envelope/", IsNullable = false)]
public partial class Envelope
{

    private EnvelopeBody bodyField;

    private string encodingStyleField;

    /// <remarks/>
    public EnvelopeBody …
Run Code Online (Sandbox Code Playgroud)

c# xml xml-namespaces deserialization

15
推荐指数
2
解决办法
2617
查看次数