<books>
<book id="1">
<name>book1</name>
<price>100</price>
</book>
<book id="2">
<name>book2</name>
<price>200</price>
</book>
<book id="3"><name>book3</name><price>300</price>
</book>
</books>
myths@business:~$ xmllint --xpath "//book[@id=2]/name/text()" sample.xml book2
myths@business:~$ xmllint --noblanks sample.xml <?xml version="1.0"?> <books><book id="1"><name>book1</name><price>100</price><license/></book><book id="2"><name>book2</name><price>200</price></book><book id="3"><name>book3</name><price>300</price></book></books>
myths@business:~$ xmllint --format sample.xml <?xml version="1.0"?> <books> <book id="1"> <name>book1</name> <price>100</price> <license/> </book> <book id="2"> <name>book2</name> <price>200</price> </book> <book id="3"> <name>book3</name> <price>300</price> </book> </books>
myths@business:~$ cat sample.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="books" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="books" msdata:IsDataSet="true" msdata:Locale="en-US">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
<xs:element name="price" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
myths@business:~$ xmllint --noout --schema sample.xsd sample.xml
sample.xml validates
myths@business:~$ cat sample.xml |xmllint --format - <?xml version="1.0"?> <?xml version="1.0"?> <books> <book id="1"> <name>book1</name> <price>100</price> <license/> </book> <book id="2"> <name>book2</name> <price>200</price> </book> <book id="3"> <name>book3</name> <price>300</price> </book> </books>
myths@business:~$ xpath -e '//book/name/text()' sample.xml Found 3 nodes in sample.xml: -- NODE -- book1 -- NODE -- book2 -- NODE -- book3
myths@business:~$ xpath -e '//book/name/text()' sample.xml 2>/dev/null book1 book2 book3 myths@business:~$ xpath -q -e '//book/name/text()' sample.xml book1 book2 book3
myths@business:~$ xmllint --xpath "//book/name/text()" sample.xml book1book2book3
myths@business:~$ cat sample.xml |xml2 /books/book/@id=1 /books/book/name=book1 /books/book/price=100 /books/book /books/book/@id=2 /books/book/name=book2 /books/book/price=200 /books/book /books/book/@id=3 /books/book/name=book3 /books/book/price=300 myths@business:~$ cat sample.xml |xml2|2xml <books><book id="1"><name>book1</name><price>100</price></book><book id="2"><name>book2</name><price>200</price></book><book id="3"><name>book3</name><price>300</price></book></books>
#!/usr/bin/env bash
tempFile=$(mktemp tmp.XXXX)
function addBook(){
id=$1
name=$2
price=$3
echo "/books/book">>$tempFile
echo "/books/book/@id=$id">>$tempFile
echo "/books/book/name=$name">>$tempFile
echo "/books/book/price=$price">>$tempFile
}
function main(){
addBook 1 book1 100
addBook 2 book2 200
addBook 3 book3 300
cat $tempFile|2xml|xmllint --format --output new_sample.xml -
rm $tempFile
}
main "$@"
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有