네임 스페이스가 필요한 XML 데이터 형식의 내보내기를 구현 중입니다. 나는 이것을하기 위해 Nokogiri XML Builder (버전 1.4.0)를 사용하고있다.Nokogiri 빌더를 사용하여 네임 스페이스가있는 루트 요소로 XML 문서 작성
그러나 Nokogiri는 네임 스페이스가있는 루트 노드를 만들 수 없습니다.
이 작동 :
Nokogiri::XML::Builder.new { |xml| xml.root('xmlns:foobar' => 'my-ns-url') }.to_xml
<?xml version="1.0"?>
<root xmlns:foobar="my-ns-url"/>
이처럼 그러나
Nokogiri::XML::Builder.new do |xml|
xml.root('xmlns:foobar' => 'my-ns-url') { xml['foobar'].child }
end.to_xml
<?xml version="1.0"?>
<root xmlns:foobar="my-ns-url">
<foobar:child/>
</root>
을, 나는 <foo:root>
같은 뭔가가 필요하고이 작동하지 않습니다
Nokogiri::XML::Builder.new { |xml| xml['foobar'].root('xmlns:foobar' => 'my-ns-url') }.to_xml
NoMethodError: undefined method `namespace_definitions' for #<Nokogiri::XML::Document:0x11bfef8 name="document">
네임 스페이스가 있어야합니다 분명히 사용하기 전에 정의되었으므로 루트 노드에 추가 할 방법이 없습니다.
a question about this on the Nokogiri mailing list을 찾았지만 답장이 없습니다. 누구나 해결책이 있습니까? 네임 스페이스가 정의되기 전에
작품. 감사! –
당신, 선생님, 많은 좌절을 덜어 줬습니다. – yalestar
안녕, yalestar. – akuhn