People who code: we want your input. Take the Survey

Questions tagged [xml]

A simple, very flexible text format that stands for eXtensible Markup Language.

Filter by
Sorted by
Tagged with
38
votes
2answers
112k 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&...
36
votes
1answer
21k 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&...
23
votes
7answers
145k 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 ...
23
votes
8answers
36k 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="...
22
votes
2answers
8k 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
1answer
26k 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
2answers
12k 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 ...
10
votes
6answers
11k 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="...
9
votes
4answers
18k 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 ...
9
votes
2answers
4k 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 ...
9
votes
3answers
28k 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&...
9
votes
2answers
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 ...
8
votes
1answer
652 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
1answer
9k 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
2answers
7k 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
1answer
579 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
1answer
6k 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 ...
5
votes
2answers
12k 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
6answers
9k 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
1answer
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
4answers
23k 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
5answers
2k 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
1answer
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
2answers
19k 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 ...
5
votes
2answers
22k 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
1answer
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
6answers
639 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
4answers
6k 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
3answers
10k 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
1answer
2k 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
2answers
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
4answers
26k 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
1answer
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
1answer
862 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
1answer
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 ...
4
votes
3answers
159 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
2answers
1k 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
4answers
8k 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. ...
4
votes
3answers
637 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&...
4
votes
1answer
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 ...
4
votes
2answers
94 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
4answers
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
2answers
4k views

Insert a multiline string into another string

I need to insert lines into an xml file : Insert <one> </one> into <tags> </tags> To obtain <tags> <one> </one> </tags> I tried this: ...
4
votes
3answers
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" /&...
3
votes
2answers
283 views

Shell script to remove child xml tags conditionally

I have a xml file having following content. <contracts> <clients> <client> <name>Nicol</name> <clientRef>123</clientRef> ...
3
votes
5answers
14k views

How to get particular string in xml using python or perl etc

from here i need to get (username) "pelech" alone this is just example in my xml file i have 1000 users. <user> <login>pelech</login> <password>passwords are saved ...
3
votes
4answers
33k views

create XML file using bash script

I want create simple xml file using bash script ( not with dom ) but when I set value in the line then echo print the $lorem word and not the val lorem=LOL echo '<root><foo a="b">$...
3
votes
2answers
7k views

Extract the Children of a Specific XML Element Type

Given a specific XML element (i.e. a specific tag name) and a snippet of XML data, I want to extract the children from each occurrence of that element. More specifically, I have the following snippet ...
3
votes
5answers
3k views

Efficient data extraction from multiple files to a single CSV file

I have a large collection of XML files with the same exact structure: $ cat file_<ID>.xml ... ... ... <double>1.2342</double> <double>2.3456</double> ...
3
votes
2answers
918 views

xslt shbang: Using xslt from the command line

I have (foolishly?) written a couple of moderately general-purpose xslt scripts. I'd quite like to turn these into executables that read an xml document from standard in or similar. The way you do ...

1
2 3 4 5
8