Questions tagged [xml]
A simple, very flexible text format that stands for eXtensible Markup Language.
402
questions
42
votes
2
answers
134k
views
How to insert variables inside a string containing ""?
I want to construct an xml string by inserinting variables:
str1="Hello"
str2="world"
xml='<?xml version="1.0" encoding="iso-8859-1"?><tag1>$str1</tag1><tag2>$str2</tag2&...
39
votes
1
answer
22k
views
Vim: Making XML text "pretty"
Is there an easy way within vi to make your XML text "pretty"?
For example:
I want this..
<person>
<name>Nick</name>
<age>26</age>
<gender&...
26
votes
9
answers
163k
views
Parse XML to get node value in bash script?
I would like to know how I can get the value of a node with the following paths:
config/global/resources/default_setup/connection/host
config/global/resources/default_setup/connection/username
...
25
votes
8
answers
39k
views
how to use patch and diff to merge two files and automatically resolve conflicts
I have read about diff and patch but I can't figure out how to apply what I need.
I guess its pretty simple, so to show my problem take these two files:
a.xml
<resources>
<color name="...
24
votes
2
answers
10k
views
VIM jump from one xml tag to the closing one
Is there a shortcut to jump from , e.g <XX> to </XX> ?
I already give it a try with '%' , but it doesn't work for this situation.
22
votes
2
answers
27k
views
Substitute text with sed and keep part of the original text
I am trying to convert
<id>1</id>
<Name>ENTERPRISE RESOURCE PLANNING</Name>
to:
<column name="id">1</column>
<column name="Name">ENTERPRISE RESOURCE ...
15
votes
2
answers
13k
views
Reformatting a large number of XML files
I am manipulating a large number of XML files scattered throughout a nested directory structure.
I tried the following:
$ find . -name "*.xml" -type f | xargs -- xmllint --format
The problem is ...
13
votes
6
answers
16k
views
Extract an attribute value from XML
Using Bash,
File:
<?xml version="1.0" encoding="UTF-8"?>
<blah>
<blah1 path="er" name="andy" remote="origin" branch="master" tag="true" />
<blah1 path="er/er1" name="...
10
votes
4
answers
21k
views
How do I parse namespaces from an XML file using XMLLINT and BASH
Below I have an example of an Adobe XML swidtag used to track inventory. I need to parse out relevant information using xmllint in bash and output that to a new text file.
For example I would like ...
10
votes
2
answers
6k
views
XML command line (shell script) manipulation
How to manipulate XML from command line in shell script?
There are many commands for manipulating tabular data, substituting environment variable or replacing text fragments with regex, but I haven't ...
10
votes
2
answers
3k
views
Parsing XML, JSON, and newer data file formats in UNIX using command line utilities
The Unix environment has some excellent tools for parsing text in various forms. However, of late, the data is not in the traditional (historical) formats (CSV, TSV, record-based or some other ...
10
votes
4
answers
32k
views
how to compare two xml files having same data in different lines?
I have two files have same data but in different lines.
File 1:
<Identities>
<Identity>
<Id>048206031415072010Comcast.USR8JR</Id>
<UID>ccp_test_79&...
8
votes
1
answer
835
views
how to massage or format html in order to parse with xmstarlet?
Do I first need to run html in the wild through something like jsoup? Not to make it valid in a human sense, might turn it to gibberish, but at least so that xmlstarlet can process the file?
...
7
votes
1
answer
8k
views
$1 not working with sed
I have a bunch of files that contain XML tags like:
<h> PIDAT <h> O
I need to delete everything what comes after the first <h> in that line, so I can get this:
<h>
For ...
7
votes
1
answer
10k
views
How to fix "cannot find -lxml2" error while installing 'igraph' for python?
On Ubuntu 15.04 I am trying to install 'igraph' using the following command:
pip install python-igraph
in order to, well, use the igraph package in python to work with graphs and stuff. However, the ...
7
votes
2
answers
8k
views
How to sort XML elements in-place?
I'm trying to version control IntelliJ IDEA configuration files. Here's a small sample:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="...
7
votes
1
answer
614
views
How can I split Openbox `rc.xml` into multiple files?
I don't like big text configuration files. So, I would like to split my rc.xml file into multiple files:
rc.xml
rc.keyboard.xml
rc.mouse.xml
6
votes
2
answers
22k
views
Search replace in XML file with sed or awk
So I have a task where by I have to manipulate an XML file through a bash shell script.
Here are the steps:
Query XML file for a value.
Take the value and cross reference it to find a new value from ...
6
votes
2
answers
23k
views
xmllint display values of more than 1 attributes in single execution
I am using xmllint to parse xml file which has several tags and each tag has several attributes. Sample structure as shown below:
<root>
<child attr1="abc" attr2="def" attr3="ghi" />
...
5
votes
6
answers
10k
views
sed first n occurrences result set between 2 tags / patterns
I have a big XML file and I get all occurrences between 2 tags:
Here is what I do:
sed -n '/<tag>/,/<\/tag>/p' file.xml
And I need to filter to get only first N occurrences.
I've ...
5
votes
2
answers
13k
views
How to parse an xml file in a shell script
I would like to know how can I split my data from the following format:
<datas>
<data>
<name>Name1</name>
</data>
<data>
<name>Name2</name>
<...
5
votes
1
answer
1k
views
XMLstarlet for JSON?
Is there a tool that is similar to XMLstarlet but works on JSON instead of XML?
My usecase: extract certain values from hierarchical JSON documents, as they are returned by some REST APIs.
Something ...
5
votes
4
answers
25k
views
How do I actually read an XML file in human form that makes sense?
I downloaded a catalog and it is in XML format. How do change it from code to human-readable form, and ideally save it as a plain text file? I've never worked/seen these before; I tried messing with ...
5
votes
1
answer
3k
views
Edit XML using xmlstarlet only in one subnode
When using the command:
-bash-4.2$ xmlstarlet ed -u "/configurations/rules/rule/branch" -v 'DAVID' config.xml > final.xml
I see that the output file was changed to DAVID, But it was changed ...
5
votes
4
answers
694
views
Can I convert fields in XML to tags using xmlstarlet?
I want to convert fields in Tags to tags within that tag for example
<book name="Data Structure" price="250" pages="350"/>
to
<book name="Data Structure&...
5
votes
5
answers
3k
views
Insert Lines after Multi-Line Regex Match
I've got an XML file I need to append to after a specific set of tags. Basically the file structure looks like this:
<key>servers</key>
<dict>
... Server Details ...
</dict>
...
5
votes
4
answers
9k
views
Using Bash to split XML data into variables
I am trying to download some files from a services. The files are found in an XML file. The XML file can have a single file or several files to download. However, now I have a problem with my script. ...
5
votes
1
answer
6k
views
Alternative to xmllint to check xml validity
Sometimes, I have to check the validity of some big xml files against a xsd file.
The biggest xml file I received had a size close to 1.5GB.
xmllint took all my RAM and almost all the swap space, for ...
5
votes
1
answer
10k
views
How do I get a list of the values of matching attributes using xmllint and xpath?
I'm trying to use xmllint to parse names of Solr cores from the configuration file.
This works:
xmllint --xpath /solr/cores/core/@name solr.xml |grep -Po '(?<=name=")[a-z-]+(?=")'
And it returns ...
5
votes
1
answer
6k
views
compare two XML files
Is there a possibility that we can compare two xml files and identify the differences in them. And then get the out put to a output new file.
I used diff xml1 xml2 but this gives me only differences ...
4
votes
6
answers
1k
views
How to find a specific tag section in an XML file?
The last few lines of my file /usr/share/glib-2.0/schemas/org.gnome.Vino.gschema.xml:
<schemalist>
<schema>
<!-- some other tags -->
<key name='notify-on-connect' type='...
4
votes
4
answers
806
views
Extracting sea level pressure from KML using Shell
I'm currently working on a little project; in a kml file called weatherdata.kml, I would like to extract the sea level pressure for each <Placemark> element. I'm trying to parse the information ...
4
votes
4
answers
7k
views
How to add an attribute in a tag in XML file by command-line?
I am trying to add field at the end of tag using sed script. Suppose I have a tag in XML file:
<book name="Sed tutorial" price="250"/>
Now I want to add field as Book_Width="A" after end of &...
4
votes
3
answers
11k
views
Delete XML node containing certain element
I want to remove all Placemarks from a KML file that contain the element <tessellate>. The following block should be wholly removed:
<Placemark>
<styleUrl>#m_ylw-pushpin330</...
4
votes
3
answers
433
views
Using sed to replace one character with another within an xml tag
I need to replace the character S with T in:
<episode-num system="onscreen">S1 E12</episode-num>
The result I expect:
<episode-num system="onscreen">T1 E12</...
4
votes
1
answer
3k
views
How to remove nodes from XML file as command line?
I have an xml file that contains the tag </w:rPr> several times. It is used like this
<w:rPr><w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/></w:rPr>
However ...
4
votes
2
answers
188
views
Deleting an XML tag in a huge file
I have difficulty parsing a huge XML file (about 100GB with large nodes). I am trying to reduce the node sizes by deleting unnecessary tags. For example, any <text> tags.
If I use native XML ...
4
votes
2
answers
1k
views
Insert some lines before a specific line with sed
I've the following file
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/usr/local/texlive/2017/texmf-dist/fonts/opentype</dir>
<...
4
votes
4
answers
33k
views
Search all xml files recursively in directory for a specific tag and grep the tag's value
Ubuntu 14.04 Trusty Tahr.
Suppose I have directory called 'testmag' which may contain 100s of xml files and directories which in turn contain many xml files as well. I don't know names of any xml ...
4
votes
2
answers
513
views
Find XML file with specific path
I'm working with XML files, each of which could be dozens of lines long. There are literally hundreds of these files, all over a directory structure. Yes, it is Magento.
I need to find the file that ...
4
votes
1
answer
5k
views
Convert xml subtitle file to srt format
I have a xml subtitle that looks like this:
<?xml version="1.0" encoding="utf-8" ?><transcript>
<Item from="1.16" duration="4.68"><![CDATA[(Dong-hyuk is coming
to see you now.)
...
4
votes
1
answer
1k
views
filter xml documents matching certains ids
Suppose you have a file containing many xml documents, like
<a>
<b>
...
</a>
in between xml documents there may be plain text log messages
<x>
...
</x>
...
How ...
4
votes
3
answers
178
views
Inserting a text between 2 patterns
I have a .xml file which contains the below
<controller-host></controller-host>
<controller-port></controller-port>
<tier-name></tier-name>
<node-name></...
4
votes
2
answers
2k
views
alter a line and remove tag using perl from xml file?
I have an xml file (client_23.xml) in which I need to alter one line and remove one whole tag from it so I came up with perl script:
In my xml file, I have a block like this. There will be only one ...
4
votes
1
answer
4k
views
How to replace "&" with "&" except when already part of an XML entity?
I have a file (xml) with many &/</>/etc, but sometimes also some & characters by themselves. I want to change this symbol to & without replacing the others.
cat ...
4
votes
2
answers
99
views
How to add a line from a list into another file when a specified line is found?
Basically I have 2 files. One has a list of router and switch login prompts, like this:
user@router1
user@router2
user@switch1
user@switch2
The other file has blocks of XML, like this:
<headTag&...
4
votes
4
answers
5k
views
How to check well-formedness of 4GB XML file?
I want to check well-formedness of a big XML file. (about 4GB.)
However, when I try xmlwf, all it tells me is
filename.xml: Value too large for defined data type
What to do with it? Is there any ...
4
votes
3
answers
2k
views
Parsing XML from a shell script
I have a datafile like this:
<Key name="com.ahsay.afc.cpf.UserGroup" content="" allowMultiple="Y">
<Value name="rsv-id" inheritParentAttribute="Y" type="string" data="1328200856753" /&...
4
votes
1
answer
3k
views
Creating new elements with xmlstarlet
I have been trying to to add new elements to an XML file.
Original file:
<levela>
<levelb>
</levelb>
</levela>
I'm trying to get the following result:
<levela>
&...
4
votes
1
answer
14k
views
Unable to write changes to a file in Vim editor
I have a 100 GB of xml doc that I'm migrating to a database in waves.
In vim, I can edit the file, but I'm unable to save changes with :wq, :q or :xx.
I get the error message this file is read only - ...