xpath internal link parsing - xpath

I have got a soap response from a webservice where it looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Body>
<multiref id="1">
<cpuclock>2300</cpuclock>
<memoryComponent>
<item href="#2"/>
<item href="#3"/>
</memoryComponent>
</multiref>
<multiref id="2" type="ns2:MemoryComponent">
<type>RAM</type>
<quantity>2048</quantity>
</multiref>
<multiref id="3" type="ns3:MemoryComponent">
<type>RAM</type>
<quantity>1024</quantity>
</multiref>
</Body>
What I am trying to achieve is to recover the memoryComponent elements.
Since I am using the XMLUtil of VBScript/QTP, I've been trying to workaround using XPATH (by predicates). Ends-with is not supported by my QTP framework version.
Any suggestions?
TIA!

I've found a way to retrieve the elements I wanted.
Set childElements = XMLFile.ChildElementsByPath("/Body/multiref[contains(#type,'MemoryComponent')]")
This workaround suits my needs pretty well.
Thanks!

Related

Modifying apk's language

I am trying to modify the language of an apk. I changed all the strings. the app has 2 languages chinese and english. I was able to change the values of chinese to arabic language. But the issue is I dont know from where I can modify the selection text. Now if I choose chinese it will change to arabic. But the selection still says chinese and english.
Language selection
Now I have found some clues but I am not good at coding so I need help.
I found this code 'bg_language_text_unfocsed.xml':
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true">
<bitmap
android:src="#ref/0x7f070068" />
</item>
<item
android:state_focused="false">
<shape>
<stroke
android:width="dimension(1073741873)"
android:color="#ref/0x7f05009a" />
</shape>
</item>
</selector>

Nokogirl scraping talk from AudioDharma page

Here is my code:
doc = Nokogiri::HTML(open("https://feeds.feedburner.com/audiodharma"))
talks = doc.css(".regularitem")
The css seems pretty straightforward, so I can't figure out why I keeping getting an empty array for 'talks'. Let me know if you see something I'm not-- Nokogiri beginner here. Thanks.
If you try to use cURL or another method to fetch the content directly, you will see your XML starts like this:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
...
As you can see, it's an XML file and not an HTML file. I'm not sure why, but Nokogiri doesn't know how to handle it properly when trying to open the URI by itself - it's an XML with some styling properties for browsers. It reads fine usually, I'm not sure about the specs more in depth.
One solution I found was to load the URL using RestClient and once the content loaded it was parsed properly. Also you should call Nokogiri's XML and call it by its name. Then the search by CSS method works without a problem:
doc = Nokogiri::XML(RestClient.get("https://feeds.feedburner.com/audiodharma"))
doc.css('.regularitem') # => has valid Nokogiri output

Maven-pdf-plugin: How to include nested items in pdf?

I'm generating a pdf document from my maven site documentation using the maven-pdf-plugin. The documentation is written in Markdown.
Unfortunately the generated document does not include nested <item> tags.
For example, I have the the following content in my site.xml:
<menu name="Documentation">
<item name="Sweets" href="sweets/sweets.html" collapse="true">
<item name="Chocolate" href="sweets/chocolate.html"/>
<item name="Bublegum" href="sweets/bublegum.html"/>
<item name="Marzipan" href="sweets/marzipan.html"/>
</item>
</menu>
In the resulting pdf I have the contents of sweets.html, but not the content of all the sub items.
I also tried using a pdf.xml file with the following content included:
<toc name="Table of Contents" depth="4">
<item name="Sweets" ref="sweets/sweets.md">
<item name="Chocolate" ref="sweets/chocolate.md"/>
<item name="Bublegum" ref="sweets/bublegum.md"/>
<item name="Marzipan" ref="sweets/marzipan.md"/>
</item>
</toc>
Which gave me the same result.
Looking at the document model reference, it should be possible to nest <item> tags.
What am I doing wrong?
Here is some additional information:
Maven: 3.3.1
maven-pdf-plugin: 1.2
doxia-module-markdown: 1.6
Using maven-pdf-plugin Version 1.3 fixed the problem.

XSLT to display news item images with consistent size

I have a RSS XML news file, which contains a list of items inclusive of a URL to an image. I also have an associated XSLT.
The problem is that the image sizes are not consistent and I want to limit the image sizes, resize them, to a nice thumbnail.
How would I modify the XSLT to accomplish that?
XML Sample:
<?xml version="1.0" encoding="UTF-8" ?>
<rss version ="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
<title>Company Name</title>
<description>Company description</description>
<link>http://www.mycompanyurl.com</link>
<item>
<title>News Item Title</title>
<link>http://www.whateverurl.com/</link>
<category>Space</category>
<pubDate>12 April 1961</pubDate>
<description>Software to reduce your job search to a half hour per day. all major job sites, job boards, classifieds. unemployment paperwork, CRM, interviews, more</description>
<image>
<url>~/App_Data/NewsControl/whatever.png</url>
<title>Whatever1</title>
<link>javascript:void(0)</link>
</image>
<g:id>1</g:id>
<g:brand>Whatever2</g:brand>
<g:condition>whatever3</g:condition>
<g:price>$whatever4</g:price>
<g:product_type>Whatever5</g:product_type>
</item>
</channel>
</rss>
Here is the associated XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<items>
<xsl:for-each select="//item">
<item Name="{position()}" HeaderText="{title}" Text="{description}" NavigateUrl="{position()}" Date="{pubDate}" ImageUrl="{image/url}"/>
</xsl:for-each>
</items>
</xsl:template>
</xsl:stylesheet>
Results of First Answer:
<items>
<xsl:for-each select="//item">
<item Name="{position()}" HeaderText="{title}" Text="{description}" NavigateUrl="{position()}" Date="{pubDate}" ImageUrl="/Tools/thumber.php?img={image/url}"/>
</xsl:for-each>
</items>
I made these changes, enabled PHP on the server (testing on from the server and locally), and saw 2 issues:
1. I get no image, merely a no image box.
If I try to edit the ImageUrl and tack on a "&W=xxx&H=xxx", the Visual Studio validator complains and throws up errors on the &.
Update 2
Here is the latest line in the XSLT:
http://myserver.com/Tools/thumber.php?img=',image/url)}"/>
The corresponding image section in the XML
<image>
<url>/Products/Jobfish/Images/Boxshots/Jobfish_DVDCaseCD_ShadowOut.jpg</url>
<title>Jobfish</title>
<link>javascript:void(0)</link>
XSLT has no built in function for resizing or thumbnailing. You will have to use an external processor for that eg. by using a PHP thumbnail generator.
Then replace the original image path with a URL pointing to your thumbnail generator, with the source being the original image.
suppose ImageUrl = mediaserver.xyz/ourlogo.jpg
the new ImageUrl would become myserver.com/thumbnailgenerator.php?src=http://mediaserver.xyz/ourlogo.jpg
Please make shure you select a caching thumbnail library (eg https://code.google.com/p/phpthumbmaker/wiki/ThumberWiki ) , since it will be a serious resource hog if you skip that. Also take into account copyright issues when re-serving these thumbnails.

Access DOM attribute with XML namespace on Freemarker template

I have the following XML.
<n:wmi xmlns:inventory="http://www.example.com/XMLSchema/mp/v1/item/ItemInventory.xsd" >
<items processMode="INCREMENTAL">
<item partnerItemId="SM-290754-US">
<action>UPDATE</action>
<inventory:availability code="AC" onHandQty="124" />
</item>
</items>
I want to access the "code" attribute in Freemarker template. Following is my freemarker template.
I tried the following templates. But none of them are working.
<#ftl ns_prefixes={"inventory":"http://www.example.com/XMLSchema/mp/v1/item/ItemInventory.xsd"}>${item["inventory:availability[#code]"]}
and
<#ftl ns_prefixes={"inventory":"http://www.example.com/XMLSchema/mp/v1/item/ItemInventory.xsd"}>${item["inventory:availability.#code"]}
I did some more investigation. The correct xpath will be
${item["inventory:availability/#code"]}

Resources