我正在实现一个自制的XMPP子协议,我正在使用StAX和JAXB的组合来解析/编组消息.当我编组一条消息时,我最终会遇到大量不需要的命名空间声明:
<ns2:auth xmlns:ns2="urn:ietf:params:xml:ns:ilf-auth"
xmlns:ns4="ilf:iq:experiment:power" xmlns:ns3="ilf:iq:experiment:init"
xmlns:ns5="ilf:iq:experiment:values" xmlns:ns6="ilf:iq:experiment:result"
xmlns:ns7="ilf:iq:experiment:stop" xmlns:ns8="ilf:iq:experiment:end">
compton@ilf</ns2:auth>
Run Code Online (Sandbox Code Playgroud)
代替:
<ns:auth xmlns:ns="urn:ietf:params:xml:ns:ilf-auth>compton@ilf</ns:auth>
Run Code Online (Sandbox Code Playgroud)
有什么办法可以转变吗?
所有这些命名空间都用在由JAXB编组/解组的不同消息中,但每条消息都使用一个命名空间.
PS.我不是XML专家,如果我犯了一些愚蠢的错误,请不要骂我;)
是否有人遇到这个"xmlns"命名空间问题(见下文)?我不能再建立我的工作项目了.
最后我尝试重新安装Android Studio并重新创建我的git存储库 - 问题仍然存在.
The prefix "xmlns" cannot be bound to any namespace explicitly; neither can the namespace for "xmlns" be bound to any prefix explicitly.
Error: The prefix "xmlns" cannot be bound to any namespace explicitly; neither can the namespace for "xmlns" be bound to any prefix explicitly.
:{project}:mergeReleaseResources FAILED
Execution failed for task ':{project}:mergeReleaseResources'.
> {project}/build/intermediates/incremental/mergeResources/release/merger.xml:1:61: Error: The prefix "xmlns" cannot be bound to any namespace explicitly; neither …Run Code Online (Sandbox Code Playgroud)我想创建以下元素:
<exercises xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mySchema.xsd">
Run Code Online (Sandbox Code Playgroud)
如果我使用这样的东西:
<xsl:element name="excercises">
<xsl:attribute name="xmlns:xsi" namespace="http://www.w3.org/2001/XMLSchema-instance"/>
Run Code Online (Sandbox Code Playgroud)
然后它创建这样的东西:
<excercises xp_0:xsi="" xmlns:xp_0="http://www.w3.org/2001/XMLSchema-instance">
Run Code Online (Sandbox Code Playgroud)
哪个看起来与我想要的相似......
我有一个以以下内容开头的xsd文档:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>
<xs:complexType name="T_segment">
<xs:sequence>
<xs:element ref="element" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="xml:space" use="required"/>
<xs:attribute ref="id" use="required"/>
</xs:complexType>
...
Run Code Online (Sandbox Code Playgroud)
当我尝试在像BizTalk这样的映射应用程序中使用这个xsd时,它会夸大抱怨命名空间.所以,我删除了xs:import namespace标签,它抱怨xs:attribute ref ="xml:space"标签.所以,我删除它,它似乎工作正常(至少不会爆炸).
我的问题是,那些标签是什么?通过删除它我打破xsd?
据我所知,命名空间是为了避免冲突.但是在xsd中,所有内容都以xs为前缀,而模式本身也有xmlns:xs ="http://www.w3.org/2001/XMLSchema".我不确定那个导入是什么.
我的代码没有返回节点
XmlDocument xml = new XmlDocument();
xml.InnerXml = text;
XmlNode node_ = xml.SelectSingleNode(node);
return node_.InnerText; // node_ = null !
Run Code Online (Sandbox Code Playgroud)
我很确定我的XML和Xpath是正确的.
我的Xpath: /ItemLookupResponse/OperationRequest/RequestId
我的XML:
<?xml version="1.0"?>
<ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05">
<OperationRequest>
<RequestId>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx</RequestId>
<!-- the rest of the xml is irrelevant -->
</OperationRequest>
</ItemLookupResponse>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,我的XPath返回的节点始终为null.有人可以帮忙吗?
当我们使用命名空间时,我们还应指出其关联的XSD所在的位置,如以下示例所示:
<?xml version="1.0"?>
<Artist BirthYear="1958"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.webucator.com/Artist"
xsi:schemaLocation="http://www.webucator.com/Artist Artist.xsd">
<Name>
<Title>Mr.</Title>
<FirstName>Michael</FirstName>
<LastName>Jackson</LastName>
</Name>
</Artist>
Run Code Online (Sandbox Code Playgroud)
在这里,我们已经指出Artist.xsd应该用于验证http://www.webucator.com/Artist命名空间.但是,我们也使用http://www.w3.org/2001/XMLSchema-instance命名空间,但我们没有指定其XSD所在的位置.XML解析器如何知道如何处理此命名空间?
更新(回应第一位评论者)
那么,我们可以代替使用:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springmodules.org/schema/ehcache
http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd">
...
</beans>
Run Code Online (Sandbox Code Playgroud)
使用
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ehcache="http://www.springmodules.org/schema/ehcache">
...
</beans>
Run Code Online (Sandbox Code Playgroud)
?
我从谷歌结帐响应中解析XML时遇到了一些麻烦.XML直接来自谷歌服务器,所以XML本身没有问题.
我想掌握所有新订单通知标签
我试过这个,但每次都返回一个空数组().
$xml = new SimpleXmlElement($raw_xml);
$notifications = $xml->xpath('notifications');
$notifications = $xml->xpath('/notification-history-response/notifications/new-order-notification');
$notifications = $xml->xpath('//new-order-notification');
Run Code Online (Sandbox Code Playgroud)
一个XML snipet(刚刚开始)
<notification-history-response xmlns="http://checkout.google.com/schema/2" serial-number="c5cda190-0eb1-4f91-87cd-e656e5598d38">
<notifications>
<new-order-notification serial-number="271578974677716-00001-7">
<buyer-billing-address>
<address1>19 sandbox st</address1>
<address2></address2>
Run Code Online (Sandbox Code Playgroud) 在下面的每个默认WPF窗口中,引用了四个名称空间.我知道:
的xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
和
的xmlns:X = "http://schemas.microsoft.com/winfx/2006/xaml"
是映射库PresentationCore.dll和PresentationFramework.dll.但是我在哪里可以找到库文件映射命名空间
的xmlns:d = "http://schemas.microsoft.com/expression/blend/2008"
和
的xmlns:MC = "http://schemas.openxmlformats.org/markup-compatibility/2006"
?
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud) 我正在使用带有SVG2VectorDrawable的Android Studio 2.0:
如果我从\RAW资源文件夹打开一个svg文件进行编辑,我用红色加下划线的文件和一个警告信息"必须声明元素svg"如下所示:
我该怎么做才能解决这个问题?
我正在使用SVG插件仅用于允许正确查看SVG XML格式的编辑器扩展
这是svg文件的内容:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Livello_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="9.693px" height="22.8px" viewBox="0 0 9.693 22.8" enable-background="new 0 0 9.693 22.8" xml:space="preserve">
<path fill-rule="evenodd" clip-rule="evenodd" fill="#616161" d="M7.703,14.038c1.248,0.911,1.99,2.36,1.99,3.916
c0,2.677-2.17,4.847-4.847,4.847C2.17,22.8,0,20.63,0,17.954c0-1.555,0.743-3.006,1.99-3.916V2.856C1.99,1.281,3.271,0,4.846,0
c1.577,0,2.856,1.279,2.856,2.856C7.702,6.583,7.702,10.311,7.703,14.038L7.703,14.038z M4.769,11.374h1.115V9.616H4.769V8.983
h1.115V7.225H4.769V6.593h1.115V4.834H4.769V4.202h1.115V2.856c0-0.573-0.464-1.037-1.037-1.037c-0.573,0-1.037,0.468-1.037,1.037
v11.42c0,0.47-0.223,0.885-0.618,1.142c-0.855,0.559-1.373,1.508-1.373,2.536c0,1.673,1.355,3.028,3.027,3.028
c1.673,0,3.028-1.355,3.028-3.028c0-1.027-0.517-1.976-1.373-2.536c-0.396-0.258-0.618-0.667-0.618-1.142v-2.27H4.769V11.374
L4.769,11.374z M4.899,20.528c0.132,0,0.239-0.108,0.239-0.239l0-0.478c0-0.132-0.108-0.239-0.239-0.239
c-0.666,0-1.207-0.54-1.207-1.206c0-0.131-0.107-0.239-0.239-0.239H2.976c-0.131,0-0.239,0.108-0.239,0.239
C2.736,19.56,3.705,20.528,4.899,20.528z"/>
</svg>
Run Code Online (Sandbox Code Playgroud) 我是xmlstarlet的新手,所以希望这个答案很简单.
我正在编写一个脚本来从命令行修改Inkscape SVG文件.我选择了xmlstarlet工具.
在测试文件上测试命令语法后,我在真正的SVG文件上遇到了麻烦.我认为使用命名空间会让我失望.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="603"
height="1000"
viewBox="0 0 159.54375 264.58334"
version="1.1"
id="svg8"
inkscape:version="0.92.1 r"
sodipodi:docname="test.svg"
inkscape:export-filename="/home/user/dev/inkscape/test/1.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96">
<defs
id="defs2">
<linearGradient
inkscape:collect="always"
id="linearGradient6204">
<stop
style="stop-color:#8f1a22;stop-opacity:1;"
offset="0"
id="stop6200" />
<stop
style="stop-color:#8f1a22;stop-opacity:0;"
offset="1"
id="stop6202" />
</linearGradient>
</defs>
</svg>
Run Code Online (Sandbox Code Playgroud)
我想换Gradient6204到Gradient9999.
我写了这个命令,它不起作用(只返回原始文件).
xmlstarlet ed -u "/svg/defs/linearGradient[@id='linearGradient6204']/@id" -v 'linearGradient9999' text.txt
Run Code Online (Sandbox Code Playgroud)
我也再次尝试,添加名称空间与-N但没有运气.我发现如果删除该行:
xmlns="http://www.w3.org/2000/svg"
Run Code Online (Sandbox Code Playgroud)
从文件然后我上面写的命令工作.
以我描述的方式更新上面的SVG文件的正确语法是什么?