xmllint

How to do command line XPath queries in huge XML files?

好久不见. 提交于 2019-12-03 12:36:23
I have a collection of XML files, and some of them are pretty big (up to ~50 million element nodes). I am using xmllint for validating those files, which works pretty nicely even for the huge ones thanks to the streaming API. xmllint --loaddtd --stream --valid /path/to/huge.xml I recently learned that xmllint is also capable of doing command line XPath queries, which is very handy. xmllint --loaddtd --xpath '/root/a/b/c/text()' /path/to/small.xml However, these XPath queries do not work for the huge XML files. I just receive a "Killed" message after some time. I tried to enable the streaming

Parsing xml to and replacing specific tags shell script

给你一囗甜甜゛ 提交于 2019-12-03 09:08:26
For the below xml ,I need to replace <studentStatus> for <studentName>CLASSA</studentName> to <studentStatus>failed</studentStatus> . <studentFile> <student> <studentName>CLASSA</studentName> <studentStatus>Success</studentStatus> <studentActions> <studentAction> <studentType>Juniour</studentType> <studentStatus>Completed</studentStatus> <studentMsg/> </studentAction> <studentAction> <studentType>HighSchool</studentType> <studentStatus>Completed</studentStatus> <studentMsg/> </studentAction> </studentActions> </student> <student> <studentName>CLASSB</studentName> <studentStatus>Success<

Native shell command set to extract node value from XML

五迷三道 提交于 2019-12-03 08:19:53
问题 I'm trying to extract the value of a node from a pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project> <parent> <groupId>org.me.labs</groupId> <artifactId>my-random-project</artifactId> <version>1.5.0</version> </parent> ... </project> I need to extract the artifactId and version from the XML using a shell command. I have the following requirements/observations: The shell script will be done within a build assembly file we use at work, so the smaller the script the better. Since it'll be

xmllint : validate an XML file against two XSD schemas (envelope / payload)

坚强是说给别人听的谎言 提交于 2019-12-03 06:59:49
问题 I am using xmllint to do some validations and I have an XML instance document which needs to validate against two schemas: one for the outer "envelope" (which includes an any element) and one for the particular payload. Say A.xsd is the envelope schema, B.xsd a payload schema (there are different possible payloads) and ab.xml a valid XML instance document (I provide an example at the end of the post). I have all three files locally available in the same directory and am using xmllint to

Native shell command set to extract node value from XML

为君一笑 提交于 2019-12-02 22:02:05
I'm trying to extract the value of a node from a pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project> <parent> <groupId>org.me.labs</groupId> <artifactId>my-random-project</artifactId> <version>1.5.0</version> </parent> ... </project> I need to extract the artifactId and version from the XML using a shell command. I have the following requirements/observations: The shell script will be done within a build assembly file we use at work, so the smaller the script the better. Since it'll be used on multiple systems (usually RHEL5), I'm looking for something that can run natively on default

xmllint : validate an XML file against two XSD schemas (envelope / payload)

依然范特西╮ 提交于 2019-12-02 21:36:51
I am using xmllint to do some validations and I have an XML instance document which needs to validate against two schemas: one for the outer "envelope" (which includes an any element) and one for the particular payload. Say A.xsd is the envelope schema, B.xsd a payload schema (there are different possible payloads) and ab.xml a valid XML instance document (I provide an example at the end of the post). I have all three files locally available in the same directory and am using xmllint to perform the validation, providing as the schema argument the location of the outer (envelope) schema:

XSD validation error: Element '{http://www.example.com}Scope': This element is not expected. Expected is ( Scope )

一曲冷凌霜 提交于 2019-12-01 16:25:50
I created the following XSD (with Eclipse): <?xml version="1.0" encoding="UTF-8"?> <schema targetNamespace="http://www.example.com" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.com"> <element name="Make"> <complexType> <sequence> <element name="Scope"></element> </sequence> </complexType> </element> </schema> and validating with this simple XML <?xml version="1.0"?> <Make xmlns="http://www.example.com"> <Scope> </Scope> </Make> gives: xmllint.exe --noout --schema sources.xsd sources.xml sources.xml:3: element Scope: Schemas validity error : Element '{http://www

XSD validation error: Element '{http://www.example.com}Scope': This element is not expected. Expected is ( Scope )

北城以北 提交于 2019-12-01 15:09:23
问题 I created the following XSD (with Eclipse): <?xml version="1.0" encoding="UTF-8"?> <schema targetNamespace="http://www.example.com" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.com"> <element name="Make"> <complexType> <sequence> <element name="Scope"></element> </sequence> </complexType> </element> </schema> and validating with this simple XML <?xml version="1.0"?> <Make xmlns="http://www.example.com"> <Scope> </Scope> </Make> gives: xmllint.exe --noout --schema

Get pom.xml version with xmllint

耗尽温柔 提交于 2019-11-30 14:01:15
问题 I have a pom.xml as such <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.qualtrics.sujitv</groupId> <artifactId>maven-test</artifactId> <packaging>jar</packaging> <version>1.2.3.4</version> <name>Test app</name> <url>http://maven.apache.org</url> </project> I am trying to use xmllint to get the

Linux Bash XMLLINT with XPATH

ⅰ亾dé卋堺 提交于 2019-11-30 12:49:10
Today I get to learn how to use xmllint properly. It does not seem to be well covered or explained. I plan to use a single language resource file to run my entire system. I have a mixture of bash scripts and php pages that must read from this language file. Currently I am using the following format in my xml file en.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <item id="index.php"> <label>LABEL</label> <value>VALUE</value> <description>DESCRIPTION</description> </item> <item id="config.php"> <label>LABEL</label> <value>VALUE</value> <description>DESCRIPTION</description> </item> <