Hi everybody
Can anybody there help me in solving the following issue.
Consider the XML
<row>
<column>Business Strategy</column>
<column>bus1</column>
</row>
<row>
<column>Company Description</column>
<column>tar1</column>
</row>
<row>
<column>Business Strategy</column>
<column>bus2</column>
</row>
<row>
<column>Company Description</column>
<column>tar2</column>
</row>
<row>
<column>Business Strategy</column>
<column>bus3</column>
</row>
<row>
<column>Company Description</column>
<column>tar3</column>
</row>
Can this xml be parsed and manipulated in ruby as
<row>
<column>Business Strategy</column>
<column>bus1</column>
<column>bus2</column>
<column>bus3</column>
</row>
<row>
<column>Company Description</column>
<column>tar1</column>
<column>tar2</column>
<column>tar3</column>
</row>
Any help would be greatly appreciated.
Thanks in advance
Anandh
El Martes, 12 de Enero de 2010, Anandh K. escribió:
<row>
</row>
<column>tar3</column>
</row>
Any help would be greatly appreciated.
Of course it can be manipulated to get your desired output. You must use
a XML
parser (I recommend Nokogiri), inspect the XML by extracting/moving the
nodes
you are interested in and generating the new XML.
Hi Anandh,
I’ve cross-posted my reply to nokogiri-talk, which is where followup
questions are probably best sent.
On Tue, Jan 12, 2010 at 6:44 AM, Anandh K.
[email protected]wrote:
<row>
</row>
<column>tar3</column>
</row>
Any help would be greatly appreciated.
This is straightforward if you know some XPath (see
xpath cover page) and Nokogiri.
I’ve posted a solution at:
The general idea is that we find the nodes we care about, and then build
a
new document with those contents.
Cheers,
-mike
Anandh
Â
Apply an XSLT with Ruby On Rails.
Please refer
http://snippets.dzone.com/posts/show/4615
Â
http://www.xml.com/pub/a/2007/01/17/making-xml-in-a-rails-app-xml-builder.html
Â
thanks
Deepak
— On Tue, 1/12/10, Anandh K. [email protected] wrote:
From: Anandh K. [email protected]
Subject: XML Manipulating
To: “ruby-talk ML” [email protected]
Date: Tuesday, January 12, 2010, 3:44 AM
Hi everybody
    Can anybody there help me in solving the following issue.
Consider the XML
  Â
      Business Strategy
      bus1
  Â
  Â
      Company Description
      tar1
  Â
  Â
     Business Strategy
     bus2
  Â
  Â
     Company Description
     tar2
  Â
  Â
      Business Strategy
      bus3
  Â
  Â
      Company Description
      tar3
  Â
Can this xml be parsed and manipulated in ruby as
  Â
      Business Strategy
      bus1
      bus2
      bus3
  Â
  Â
      Company Description
      tar1
      tar2
      tar3
  Â
Any help would be greatly appreciated.
Thanks in advance
Anandh
<?xml version="1.0"?>
Business Strategy
aaaa
aaaaa
gggg
<?xml version="1.0"?>
Company Description
bbbb
bbbb
fhghj
<?xml version="1.0"?>
Business Strategy
aaaa
aaaaa
gggg
<?xml version="1.0"?>
Company Description
bbbb
bbbb
fhghj
Consider the above XML. Is there anyway to remove “<?xml
version="1.0"?>” and also the duplicate block with same data.
For example consider the following identical blocks
<?xml version="1.0"?>
Business Strategy
aaaa
aaaaa
gggg
<?xml version="1.0"?>
Business Strategy
aaaa
aaaaa
gggg
The resulting xml should remove the duplicate block and should contain
only one.
Any help would be appreciated.
Thanks in Advance
Anandh
Anandh K. wrote:
Thanks mike. The solution solved my problem to a greater extent but with
one issue.
In the resulting solution which is as follows
Business Strategy
bus1
bus2
bus3
Company Description
tar1
tar2
tar3
Can you suggest me how can i avoid “<?xml version="1.0"?>”.
If i give some thing like this
puts new_doc.to_xml(:dasherize => false, :skip_instruct=>true)
Ruby compiler threw argument error.
Any help would be appreciated.
Thanks
Anandh
Mike D. wrote:
Hi Anandh,
I’ve cross-posted my reply to nokogiri-talk, which is where followup
questions are probably best sent.
On Tue, Jan 12, 2010 at 6:44 AM, Anandh K.
[email protected]wrote:
<row>
</row>
<column>tar3</column>
</row>
Any help would be greatly appreciated.
This is straightforward if you know some XPath (see
xpath cover page) and Nokogiri.
I’ve posted a solution at:
xml.rb · GitHub
The general idea is that we find the nodes we care about, and then build
a
new document with those contents.
Cheers,
-mike
Thanks mike. The solution solved my problem to a greater extent but with
one issue.
In the resulting solution which is as follows
Business Strategy
bus1
bus2
bus3
Company Description
tar1
tar2
tar3
Can you suggest me how can i avoid “<?xml version="1.0"?>”.
If i give some thing like this
puts new_doc.to_xml(:dasherize => false, :skip_instruct=>true)
Ruby compiler threw argument error.
Any help would be appreciated.
Thanks
Anandh
Mike D. wrote:
Hi Anandh,
I’ve cross-posted my reply to nokogiri-talk, which is where followup
questions are probably best sent.
On Tue, Jan 12, 2010 at 6:44 AM, Anandh K.
[email protected]wrote:
<row>
</row>
<column>tar3</column>
</row>
Any help would be greatly appreciated.
This is straightforward if you know some XPath (see
xpath cover page) and Nokogiri.
I’ve posted a solution at:
xml.rb · GitHub
The general idea is that we find the nodes we care about, and then build
a
new document with those contents.
Cheers,
-mike
Dear Mike
Can this be done using Hpricot. I tried doing with Hpricot. But
Hpricot doesnot support xpath. It support something called “search”.With
that too I could not get my desired result since it doesnot support
“following-sibling” property.
Any help would be appreciated.
Thanks
Anandh
Mike D. wrote:
Hi Anandh,
I’ve cross-posted my reply to nokogiri-talk, which is where followup
questions are probably best sent.
On Tue, Jan 12, 2010 at 6:44 AM, Anandh K.
[email protected]wrote:
<row>
</row>
<column>tar3</column>
</row>
Any help would be greatly appreciated.
This is straightforward if you know some XPath (see
xpath cover page) and Nokogiri.
I’ve posted a solution at:
xml.rb · GitHub
The general idea is that we find the nodes we care about, and then build
a
new document with those contents.
Cheers,
-mike