标签: xml-namespaces

在编组时如何向JAXB中的元素添加命名空间属性?

我正在使用eBay的LMS(大型商户服务),并一直遇到错误:

org.xml.sax.SAXException:SimpleDeserializer在尝试反序列化时遇到了一个不期望的子元素.

经过大量的反复试验后,我追查了问题.事实证明这是有效的:

<?xml version="1.0" encoding="UTF-8"?>
<BulkDataExchangeRequests xmlns="urn:ebay:apis:eBLBaseComponents">
  <Header>
    <Version>583</Version>
    <SiteID>0</SiteID>
  </Header>
  <AddFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
Run Code Online (Sandbox Code Playgroud)

虽然这(我发送的内容)不是:

<?xml version="1.0" encoding="UTF-8"?>
<BulkDataExchangeRequests xmlns="urn:ebay:apis:eBLBaseComponents">
  <Header>
    <Version>583</Version>
    <SiteID>0</SiteID>
  </Header>
  <AddFixedPriceItemRequest>
Run Code Online (Sandbox Code Playgroud)

区别在于xml命名空间属性AddFixedPriceItemRequest.我的所有XML目前都是通过JAXB进行编组的,我不确定将第二个xmlns属性添加到文件中的其他元素的最佳方法是什么.

这就是问题所在.如何在JAXB中将xmlns属性添加到另一个元素?

更新:

package ebay.apis.eblbasecomponents;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AddFixedPriceItemRequestType", propOrder = {
    "item"
})
public class AddFixedPriceItemRequestType
    extends AbstractRequestType
{

    @XmlElement(name = "Item")
    protected ItemType item;

    public ItemType getItem() {
        return item;
    }

    public void setItem(ItemType value) {
        this.item = value;
    }
} …
Run Code Online (Sandbox Code Playgroud)

java xml jaxb xml-namespaces

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

XPath表达式不返回//元素,但//*返回计数

我正在使用带有以下示例数据的XOM:

Element root = cleanDoc.getRootElement();
//find all the bold elements, as those mark institution and clinic.
Nodes nodes = root.query("//*");

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml">
    <head>
        <title>Patient Information</title>
    </head>
</html>
Run Code Online (Sandbox Code Playgroud)

以下元素返回许多元素(来自实际数据):

//*
Run Code Online (Sandbox Code Playgroud)

但有点像

//head
Run Code Online (Sandbox Code Playgroud)

什么都不返回 如果我遍历根的子节点,数字似乎匹配,如果我打印元素名称,一切看起来都是正确的.

我正在使用HTML,使用tagsoup解析它,然后从结果字符串构建XOM文档.这部分可能会出现如此可怕的错误?我觉得这里有一些奇怪的编码问题,但我只是没有看到它.Java字符串是字符串,对吧?

java xpath tag-soup xml-namespaces xom

4
推荐指数
1
解决办法
1571
查看次数

使lxml.objectify忽略xml名称空间?

所以我要处理一些看起来像这样的xml:

<ns2:foobarResponse xmlns:ns2="http://api.example.com">
  <duration>206</duration>
  <artist>
    <tracks>...</tracks>
  </artist>
</ns2:foobarResponse>
Run Code Online (Sandbox Code Playgroud)

我找到了lxml和它的objectify模块,它允许你以pythonic方式遍历xml文档,就像字典一样.
问题是:每次尝试访问元素时都使用伪造的xml命名空间,如下所示:

from lxml import objectify

tree = objectify.fromstring(xml)
print tree.artist
# ERROR: no such child: {http://api.example.com}artist
Run Code Online (Sandbox Code Playgroud)

它正在尝试使用<artist>父命名空间进行访问,但标记不使用ns.

任何想法如何解决这个问题?谢谢

python xml lxml xml-namespaces

4
推荐指数
1
解决办法
2806
查看次数

将属性添加到asp.net中的<HTML>元素?

我想<HTML>在asp.net中为元素添加两个额外的xml命名空间:

采取:

<html xmlns="http://www.w3.org/1999/xhtml" >
Run Code Online (Sandbox Code Playgroud)

制作(添加facebook开放图形命名空间):

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:og="http://ogp.me/ns#"
      xmlns:fb="http://www.facebook.com/2008/fbml">
Run Code Online (Sandbox Code Playgroud)

我如何访问<HTML>后面的代码中的元素并添加命名空间?

html c# asp.net xml-namespaces

4
推荐指数
1
解决办法
9363
查看次数

XML模式/命名空间

我经常在XML模式文件中看到类似下面的代码.据我所知,xmlns是定义一个新的命名空间.但是,跟随xmlns的长URL是否真的有必要?我的意思是程序,解析器,还是真正调用的,例如"http://www.springframework.org/schema/beans"?或者这条线就像这样:

<beans xmlns="beansNamespace">
Run Code Online (Sandbox Code Playgroud)

这是其中之一

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
    http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
"
>
Run Code Online (Sandbox Code Playgroud)

xml xsd xml-namespaces

4
推荐指数
1
解决办法
360
查看次数

WCF命名空间用法

好的 - 直接和简单的问题(2部分) - 寻找一个简单的答案.

在WCF服务合同中,您可以在合同上提供命名空间......

问题是这样的:第一个 - 为什么(对于真正...需要可靠的细节)是为合同命名空间命名约定选择的http://模型

第二 - 一旦设定,我该如何利用...像这样?这是在我的主人 -

    <endpoint ... contract="http://helloworld.com/example"></endpoint>
Run Code Online (Sandbox Code Playgroud)

wcf xml-namespaces servicecontract

4
推荐指数
1
解决办法
3127
查看次数

无法使用PHP Simplexml添加带有命名空间前缀的属性

尝试编辑使用Excels XML-Namespaces的XML文档:

<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
          xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
Run Code Online (Sandbox Code Playgroud)

我需要得到这个结果(需要ss:前缀befire 类型):

<Cell ...><Data ss:Type="String">value</Data></Cell>
Run Code Online (Sandbox Code Playgroud)

我已经查看了无法使用PHP SimpleXML添加命名空间的问题,但这种方法在这里没有帮助.换句话说,按照那里的说明运行它

$data = $cells[$i]->addChild('Data','value'); 
$data->addAttribute("ss:Type","String","urn:schemas-microsoft-com:office:spreadsheet");
Run Code Online (Sandbox Code Playgroud)

给我

<Cell ...><Data Type="String">value</Data></Cell>
Run Code Online (Sandbox Code Playgroud)

没有ss:前缀.如果我删除urn:前缀,那么我得到了这个

<Cell ...><Data xmlns:ss="schemas-microsoft-com:office:spreadsheet" ss:Type="String">value</Data></Cell>
Run Code Online (Sandbox Code Playgroud)

在任何一种情况下,当我用Excel打开文档时,数据都是不可见的.随着瓮:在SS:缺失和不瓮:定义成为部分 在Excel中无效的元素.

php xml simplexml xml-namespaces

4
推荐指数
1
解决办法
2822
查看次数

不合格的XSD全局属性引用

以下XML模式无法使用以下XML实例文档进行验证.有没有办法重写模式,以便实例文档在给定的约束内验证?

约束

  • 该属性不能是元素的本地属性
  • 实例文档必须保持不变

(无效)架构

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/XMLSchema.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:attribute name="sample-attribute" type="xs:string" />

    <xs:element name="sample-element">
        <xs:complexType>
            <xs:attribute ref="sample-attribute" use="required" />
        </xs:complexType>
    </xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

例

<?xml version="1.0" encoding="utf-8"?>
<sample-element xmlns="http://tempuri.org/XMLSchema.xsd" sample-attribute="test" />
Run Code Online (Sandbox Code Playgroud)

xml xsd xml-namespaces

4
推荐指数
2
解决办法
2431
查看次数

javax.faces.view.facelets.FaceletException:Error Parsing /my.xhtml:Error Traced [line:42]元素"f:facet"的前缀"f"未绑定

我想创建一个可以将数据从数据库显示到JSF页面的表.我找到了这段代码:

<h:dataTable value="#{bookStore.items}" var="store">
  <h:column>
    <f:facet name="header">
      <h:outputText  value="#{msg.storeNameLabel}"/>
    </f:facet>
    <h:outputText value="#{store.name}"/>
  </h:column>
  <h:column>
    <f:facet name="header">
      Subject
    </f:facet>
    <h:outputText value="#{store.subject}"/>
  </h:column>
  <h:column>
    <f:facet name="header">
      <h:outputText  value="#{msg.storePriceLabel}"/>
    </f:facet>
    <h:outputText value="#{store.price}"/>
  </h:column>
</h:dataTable> 
Run Code Online (Sandbox Code Playgroud)

当我使用此代码时,我在Netbeans中收到此错误消息:

javax.faces.view.facelets.FaceletException:Error Parsing /my.xhtml:Error Traced [line:42]元素"f:facet"的前缀"f"未绑定

如果我用f标签替换h标签,它会起作用吗?或者我是否必须包含f标签库?

jsf facelets prefix xml-namespaces

4
推荐指数
1
解决办法
9051
查看次数

如何让ServiceStack从带有XML命名空间的TFS接收XML请求

我正在尝试将TFS 2012事件通知连接到ServiceStack,但我只是不断收到错误:

{
    "responseStatus": {
        "errorCode": "RequestBindingException",
        "message": "Unable to bind request",
        "stackTrace": "at ServiceStack.WebHost.Endpoints.RestHandler.GetRequest(IHttpRequest httpReq, IRestPath restPath)\r\n   
                       at ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest (IHttpRequest httpReq, IHttpResponse httpRes, String operationName)"
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的DTO(它包含了我尝试使其工作的一些部分).

[Route("/releasemanagement/tfsevents/buildcomplete", "POST")]
[DataContract(Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public class TfsEventBuildComplete : IReturn<BuildCompleteResponse>
{
    [DataMember]
    public string BuildUri { get; set; }

    [DataMember]
    public string TeamFoundationServerUrl { get; set; }

    [DataMember]
    public string TeamProject { get; set; }

    [DataMember]
    public string Title { get; set; }

    [DataMember]
    public string Id { get; set; } …
Run Code Online (Sandbox Code Playgroud)

tfs xml-namespaces servicestack

4
推荐指数
1
解决办法
673
查看次数

标签 统计

xml-namespaces ×10

xml ×5

java ×2

xsd ×2

asp.net ×1

c# ×1

facelets ×1

html ×1

jaxb ×1

jsf ×1

lxml ×1

php ×1

prefix ×1

python ×1

servicecontract ×1

servicestack ×1

simplexml ×1

tag-soup ×1

tfs ×1

wcf ×1

xom ×1

xpath ×1