I have a XML like
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>Vaidyanathan Nagarajan</author>
</book>
<book category="it" cover="paperback">
<title lang="en">Learning XML</title>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
When I evaluate the XPATH
/bookstore/book/author/parent::book
I get the result:
/bookstore[1]/book[1]
/bookstore[1]/book[2]
But as the second has three -nodes I am searching for a XPATH expression that gives me back the following:
/bookstore[1]/book[1]
/bookstore[1]/book[2]
/bookstore[1]/book[2]
/bookstore[1]/book[2]
Is this possible?
Thanks
Regards
Mario
I got a solution, the XPATH
//author!parent::book/path()
returns:
/Q{}bookstore[1]/Q{}book[2]
/Q{}bookstore[1]/Q{}book[2]
/Q{}bookstore[1]/Q{}book[2]
/Q{}bookstore[1]/Q{}book[2]
Thanks
Regards
Mario
Related
I am using xml_edit to change the value of xml. This is not working with below scenario.
I want to change the title of Atwood, Margaret author in Second Bookshelf in below xml:
<?xml version="1.0"?>
<bookshelf>
<Name>First Bookshelf</Name>
<book>
<author>Conway, Damien</author>
<title>Perl Best Practices</title>
</book>
<book>
<author>Atwood, Margaret</author>
<title>Perl Best Practices</title>
</book>
</bookshelf>
<bookshelf>
<Name>Second Bookshelf</Name>
<book>
<author>Conway, Damien</author>
<title>Perl Best Practices</title>
</book>
<book>
<author>Atwood, Margaret</author>
<title>Perl Best Practices</title>
</book>
</bookshelf>
I am trying to use below recipe. I do't know, how could I verify the Name and auther of second bookshelf.
xml_edit 'change title' do
path 'C:\\testing\\text.xml'
target '/bookshelf/book/title[text()=\'Perl Best Practices\']'
fragment '<title>Hello World</title>'
action :replace
end
It looks like your xml is not valid
It should look like:
<?xml version="1.0"?>
<shelves>
<bookshelf>
<Name>First Bookshelf</Name>
<book>
<author>Conway, Damien</author>
<title>Perl Best Practices</title>
</book>
<book>
<author>Atwood, Margaret</author>
<title>Perl Best Practices</title>
</book>
</bookshelf>
<bookshelf>
<Name>Second Bookshelf</Name>
<book>
<author>Conway, Damien</author>
<title>Perl Best Practices</title>
</book>
<book>
<author>Atwood, Margaret</author>
<title>Perl Best Practices</title>
</book>
</bookshelf>
</shelves>
With that in mind you can do:
xml_edit 'change title' do
path 'C:\\testing\\text.xml'
target '/shelves/bookshelf[Name[text()=\'Second Bookshelf\']]/book[author[text()=\'Atwood, Margaret\']]/title'
fragment '<title>Hello World</title>'
action :replace
end
How can i get the list of categories a product is a member of, using the Magento v2.0 SOAP web service?
On http://devdocs.magento.com/guides/v2.0/soap/bk-soap.html i found a list of services.
With the catalogProductRepositoryV1, i can request a list or a single product, but it doesn't contain the categories. eg:
Request:
POST http://domain/soap/default?services=catalogProductRepositoryV1 HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8; action="catalogProductRepositoryV1Get"
Host: domain
Content-Length: 382
Expect: 100-continue
Accept-Encoding: gzip, deflate
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<catalogProductRepositoryV1GetRequest xmlns="http://domain/soap/default?services=catalogProductRepositoryV1">
<sku xmlns="">24-MB01</sku>
</catalogProductRepositoryV1GetRequest>
</s:Body>
</s:Envelope>
Response:
HTTP/1.1 200 OK
Date: Fri, 20 May 2016 12:21:46 GMT
Server: Apache/2.4.18 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4 PHP/5.6.21
X-Powered-By: PHP/5.6.21
Set-Cookie: PHPSESSID=89fdd89a6caeb8be424b9531c69d6c69; expires=Fri, 20-May-2016 13:21:47 GMT; Max-Age=3600; path=/; domain=domain; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 5547
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Connection: close
Content-Type: application/soap+xml; charset=utf-8
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://domain/soap/default?services=catalogProductRepositoryV1">
<env:Body>
<ns1:catalogProductRepositoryV1GetResponse>
<result>
<id>1</id>
<sku>24-MB01</sku>
<name>Joust Duffle Bag</name>
<attributeSetId>15</attributeSetId>
<price>34</price>
<status>1</status>
<visibility>4</visibility>
<typeId>simple</typeId>
<createdAt>2016-01-22 16:28:25</createdAt>
<updatedAt>2016-04-20 09:51:54</updatedAt>
<extensionAttributes/>
<productLinks>
<item>
<sku>24-MB01</sku>
<linkType>upsell</linkType>
<linkedProductSku>24-MB03</linkedProductSku>
<linkedProductType>simple</linkedProductType>
<position/>
<extensionAttributes/>
</item>
<item>
<sku>24-MB01</sku>
<linkType>upsell</linkType>
<linkedProductSku>24-MB05</linkedProductSku>
<linkedProductType>simple</linkedProductType>
<position/>
<extensionAttributes/>
</item>
<item>
<sku>24-MB01</sku>
<linkType>upsell</linkType>
<linkedProductSku>24-MB06</linkedProductSku>
<linkedProductType>simple</linkedProductType>
<position/>
<extensionAttributes/>
</item>
<item>
<sku>24-MB01</sku>
<linkType>upsell</linkType>
<linkedProductSku>24-MB02</linkedProductSku>
<linkedProductType>simple</linkedProductType>
<position/>
<extensionAttributes/>
</item>
<item>
<sku>24-MB01</sku>
<linkType>upsell</linkType>
<linkedProductSku>24-UB02</linkedProductSku>
<linkedProductType>simple</linkedProductType>
<position/>
<extensionAttributes/>
</item>
<item>
<sku>24-MB01</sku>
<linkType>upsell</linkType>
<linkedProductSku>24-WB03</linkedProductSku>
<linkedProductType>simple</linkedProductType>
<position/>
<extensionAttributes/>
</item>
<item>
<sku>24-MB01</sku>
<linkType>upsell</linkType>
<linkedProductSku>24-WB07</linkedProductSku>
<linkedProductType>simple</linkedProductType>
<position/>
<extensionAttributes/>
</item>
<item>
<sku>24-MB01</sku>
<linkType>upsell</linkType>
<linkedProductSku>24-WB04</linkedProductSku>
<linkedProductType>simple</linkedProductType>
<position/>
<extensionAttributes/>
</item>
</productLinks>
<options/>
<mediaGalleryEntries>
<item>
<id>1</id>
<mediaType>image</mediaType>
<label>Image</label>
<position>1</position>
<disabled>false</disabled>
<types>
<item>image</item>
<item>small_image</item>
<item>thumbnail</item>
</types>
<file>/m/b/mb01-blue-0.jpg</file>
</item>
</mediaGalleryEntries>
<tierPrices/>
<customAttributes>
<item>
<attributeCode>description</attributeCode>
<value><p>The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places to go.</p>
<ul>
<li>Dual top handles.</li>
<li>Adjustable shoulder strap.</li>
<li>Full-length zipper.</li>
<li>L 29" x W 13" x H 11".</li>
</ul></value>
</item>
<item>
<attributeCode>meta_title</attributeCode>
<value>Joust Duffle Bag</value>
</item>
<item>
<attributeCode>meta_keyword</attributeCode>
<value>Joust Duffle Bag</value>
</item>
<item>
<attributeCode>meta_description</attributeCode>
<value>Joust Duffle Bag <p>The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places t</value>
</item>
<item>
<attributeCode>image</attributeCode>
<value>/m/b/mb01-blue-0.jpg</value>
</item>
<item>
<attributeCode>small_image</attributeCode>
<value>/m/b/mb01-blue-0.jpg</value>
</item>
<item>
<attributeCode>thumbnail</attributeCode>
<value>/m/b/mb01-blue-0.jpg</value>
</item>
<item>
<attributeCode>category_ids</attributeCode>
<value>
<xsd:string>3</xsd:string>
<xsd:string>4</xsd:string>
</value>
</item>
<item>
<attributeCode>options_container</attributeCode>
<value>container2</value>
</item>
<item>
<attributeCode>required_options</attributeCode>
<value>0</value>
</item>
<item>
<attributeCode>has_options</attributeCode>
<value>0</value>
</item>
<item>
<attributeCode>image_label</attributeCode>
<value>Image</value>
</item>
<item>
<attributeCode>small_image_label</attributeCode>
<value>Image</value>
</item>
<item>
<attributeCode>thumbnail_label</attributeCode>
<value>Image</value>
</item>
<item>
<attributeCode>msrp_display_actual_price_type</attributeCode>
<value>0</value>
</item>
<item>
<attributeCode>url_key</attributeCode>
<value>joust-duffle-bag</value>
</item>
<item>
<attributeCode>tax_class_id</attributeCode>
<value>0</value>
</item>
<item>
<attributeCode>activity</attributeCode>
<value>11,19,21,22</value>
</item>
<item>
<attributeCode>style_bags</attributeCode>
<value>25,26,29</value>
</item>
<item>
<attributeCode>material</attributeCode>
<value>37,38</value>
</item>
<item>
<attributeCode>strap_bags</attributeCode>
<value>61,62,63,64,65,66</value>
</item>
<item>
<attributeCode>features_bags</attributeCode>
<value>74,76,79</value>
</item>
<item>
<attributeCode>eco_collection</attributeCode>
<value>0</value>
</item>
<item>
<attributeCode>performance_fabric</attributeCode>
<value>0</value>
</item>
<item>
<attributeCode>erin_recommends</attributeCode>
<value>0</value>
</item>
<item>
<attributeCode>new</attributeCode>
<value>0</value>
</item>
<item>
<attributeCode>sale</attributeCode>
<value>0</value>
</item>
<item>
<attributeCode>eboekhouden_grootboekrekening</attributeCode>
<value>8000</value>
</item>
<item>
<attributeCode>eboekhouden_costcenter</attributeCode>
<value>0</value>
</item>
</customAttributes>
</result>
</ns1:catalogProductRepositoryV1GetResponse>
</env:Body>
</env:Envelope>
in the product detail SOAP Call i.e. catalogProductRepositoryV1
you will find category_ids as an item in customAttributes tag
<customAttributes>
...
<item>
<attributeCode>category_ids</attributeCode>
<value>
<xsd:string>3</xsd:string>
<xsd:string>4</xsd:string>
</value>
</item>
...
</customAttributes>
than you need to load the categories if you want any information of that from catalogCategoryRepositoryV1
This is the XML input:
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
I am using BaseX 7.9. When I request attributes,
for $book in collection()/bookstore/book
return $book/#*
an error occurs:
[SENR0001] Attributes cannot be serialized: attribute category {"COOKING"}.
How can this be fixed? Thanks for helping me!
The XQuery 3.1 Serialization specification provides the new "adaptive" serialization mode, which allows the serialization of attribute and namespace nodes. Since Version 8.0 of BaseX, this mode is used as new default.
This was different in earlier versions of the specification, which did not allow attributes to be output on their own (see the error code SENR0001 for more information).
This is the structure of the file I need to import.
<channel>
<item>
<type>image</type>
<title>title image</title>
<id>1</id>
<image_url>url_to_image</image_url>
</item>
<item>
<type>page</type>
<title>node title</title>
<id>2</id>
<ref>
<entity>image_ref</entity>
<ref_value>1</ref_value>
</ref>
<ref>
<entity>category</entity>
<ref_value>5</ref_value>
</ref>
</item>
</channel>
In the page item the tag contains the id of the image item.
How do I add the image url from the image item to the page item?
I'm trying to use
/channel/item[id=ref/ref_value[../entity/text() = 'image_ref']]/image_url but it does not work...
What's the XPath expression to not import the image item but just the page item?
Thanks in advance
Use:
/*/item[type='image' and id=../item[type='page']
/ref[entity = 'image_ref']/ref_value]
/image_url/text()
XSLT - based verification:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:copy-of select=
"/*/item[type='image' and id=../item[type='page']
/ref[entity = 'image_ref']/ref_value]
/image_url/text()"/>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied to the provided XML document:
<channel>
<item>
<type>image</type>
<title>title image</title>
<id>1</id>
<image_url>url_to_image</image_url>
</item>
<item>
<type>page</type>
<title>node title</title>
<id>2</id>
<ref>
<entity>image_ref</entity>
<ref_value>1</ref_value>
</ref>
<ref>
<entity>category</entity>
<ref_value>5</ref_value>
</ref>
</item>
</channel>
the XPath expression is evaluated and the result of this evaluation is copied to the output:
url_to_image
Update:
The OP has implied in comments that there may be many "page items" and "image items" and that he needs an expression, getting the image url for only a specific page.
This XPath expression:
/*/item[type='image'
and id=../item[type='page'][1]
/ref[entity = 'image_ref']/ref_value
]
/image_url/text()"/>
produces the wanted image url for the first "page item" in the following XML document:
<channel>
<item>
<type>image</type>
<title>title image</title>
<id>1</id>
<image_url>url_to_image</image_url>
</item>
<item>
<type>image</type>
<title>title image</title>
<id>2</id>
<image_url>url2_to_image</image_url>
</item>
<item>
<type>page</type>
<title>node title</title>
<id>3</id>
<ref>
<entity>image_ref</entity>
<ref_value>1</ref_value>
</ref>
<ref>
<entity>category</entity>
<ref_value>5</ref_value>
</ref>
</item>
<item>
<type>page</type>
<title>node title</title>
<id>4</id>
<ref>
<entity>image_ref</entity>
<ref_value>2</ref_value>
</ref>
<ref>
<entity>category</entity>
<ref_value>5</ref_value>
</ref>
</item>
</channel>
The result produced is:
url_to_image
To get the wanted url for the second page item, we simply modify the above XPath expression to:
/*/item[type='image'
and id=../item[type='page'][2]
/ref[entity = 'image_ref']/ref_value
]
/image_url/text()"/>
and now the result is:
url2_to_image
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="https://extranet.mcs.be/DEV_QUALITY_API/modules/quality/services/soap/quality.php"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getQuestionnairesListResponse>
<return SOAP-ENC:arrayType="ns1:QuestionnaireListItem[34]"
xsi:type="ns1:ArrayOfQuestionnaireListItem">
<item xsi:type="ns1:QuestionnaireListItem">
<ID xsi:type="xsd:string">0000000022</ID>
<Code xsi:type="xsd:string">Interest PubTransp</Code>
<Reference xsi:type="xsd:string">Check Employees Interest in Public
Transport</Reference>
</item>
<item xsi:type="ns1:QuestionnaireListItem">
<ID xsi:type="xsd:string">0000000008</ID>
<Code xsi:type="xsd:string">CS SRE North 2003</Code>
<Reference xsi:type="xsd:string">Customer Satisfaction SRE North 2003</Reference>
</item>
<item xsi:type="ns1:QuestionnaireListItem">
<ID xsi:type="xsd:string">0000000006</ID>
<Code xsi:type="xsd:string">CS SRE South 2003</Code>
<Reference xsi:type="xsd:string">Customer Satisfaction SRE South 2003</Reference>
</item>
.
.
.
I want to parse the above soap String (I actually want to get items from the above soap). How could I do this?
There's a gem called Savon that's specifically made for dealing with SOAP in Ruby.
There's good documentation on the web site, once you looked into that and have more specific questions I'm sure we can help you.