I would like to receive the output:
10.62.197.125, 10.62.197.126, 10.62.197.127.
How do I make that happen? (Note that the code has been somehow manipulated due to customer restrictions).
<output arrayType="ns2:aaa[20]" type="ns2:aaa_array">
<item type="ns2:bbb">
<ip_addr type="xsd:string">0a2ef556</ip_addr>
<hostaddr type="xsd:string">10.62.197.125</hostaddr>
<subnet_name type="xsd:string">Test</subnet_name>
<pool_id type="xsd:string">0</pool_id>
</item>
<item type="ns2:aaa">
<ip_addr type="xsd:string">0a3c3c33</ip_addr>
<hostaddr type="xsd:string">10.62.197.126</hostaddr>
<subnet_name type="xsd:string">Test</subnet_name>
<pool_id type="xsd:string">0</pool_id>
</item>
<item type="ns2:aaa">
<ip_addr type="xsd:string">0a3a72c4</ip_addr>
<hostaddr type="xsd:string">10.62.197.127</hostaddr>
<subnet_name type="xsd:string">Test</subnet_name>
<pool_id type="xsd:string">0</pool_id>
</item>
</output>
To get the elements:
/*/item/hostaddr/text()
results in
10.62.197.125
10.62.197.126
10.62.197.127
To get a string (supported by XPath 2.0+):
string-join(/*/item/hostaddr/text(), ', ')
results in
10.62.197.125, 10.62.197.126, 10.62.197.127
This means:
Select the text in the hostaddr element in all item elements.
Test:
You can test this by going to a XPath tester, like this, paste your XML in Option 1, paste the expression in XPath expression field and press the test XPath button.
Related
Is this possible? I need to edit the following xml file. For every "BASerialKeyND", I need to replace the 987654321 right underneath it. Same thing for "BASerialKey" and 98-7654-321. I cannot count the lines in the file and assign it to a variable and then replace those specific lines because BASerialKeyND and BASerialKey occur on different lines in different files.
Thanks so much for your help!!!!!!!!!!
<?xml version="1.0" encoding="utf-8"?>
<SerializableDictionary>
<item>
<key>BASerialKeyND</key>
<value>987654321</value>
</item>
<item>
<key>BASerialKey</key>
<value>98-7654-321</value>
</item>
<item>
<key>MACHINETYPE</key>
<value>Max</value>
</item>
<item>
<key>PC1NAME</key>
<value>987654321PC1</value>
</item>
<item>
<key>PC2NAME</key>
<value>987654321PC2</value>
</item>
<item>
<key>REPORTPRINTER</key>
<value>None</value>
</item>
<item>
<key>PC1PRINTERS</key>
<value>Name=Microsoft XPS Document Writer
</SerializableDictionary>
I write web project on c++. In my c++ code has to insert html, for example such
void CPage::putBaseFooter() {
if(m_canRender) {
HTML(
<!++
</main>
<footer>
<f++ composePageFooter(); ++f>
</footer>
</body>
</html>
++!>);
}
}
That is the whole html code is between <!++ and ++!> (Code is processed before compiling its own preprocessor to string)
Just have your own macros preprocessor, such as for example
<f++ composeHead(); ++f>
<v++ ts.tm_year + 1900++v>
<paged_list++ [day_tasks_control] [/tasks/list] [taskListRenderer]>
...
<++paged_list>
<labeled_control++ [Description] [taskDescription]>
<textarea></textarea>
<++labeled_control>
Tell me please, how i can highlite html keywords and own macroses into qt-creator code editor? I tried to write a higlite-xml for Kate (with inheritance c++ highlite), but probably something I do not understand, since the backlight does not work.
Here are my sketches syntax highlighting
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd"
[
<!ENTITY space " ">
<!ENTITY separators ",;">
<!ENTITY ns_punctuators "!%&space;&()+-/.*<=>?[]{|}~^&separators;">
]>
<!--
Copyright (c) 2012 by Alex Turbov (i.zaufi#gmail.com)
-->
<language
name="C++"
section="Sources"
version="1.0"
kateversion="2.4"
indenter="cstyle"
style="C++"
mimetype="text/x-c++src;text/x-c++hdr;text/x-chdr"
extensions="*.c++;*.cxx;*.cpp;*.cc;*.C;*.h;*.hh;*.H;*.h++;*.hxx;*.hpp;*.hcc;*.moc"
author="Sheridan (gorlov.maxim#gmail.com)"
license="LGPL"
priority="11"
>
<highlighting>
<list name="InplaceHTML">
<item> form </item>
<item> table </item>
<item> div </item>
<item> td </item>
<item> tr </item>
<item> th </item>
<item> span </item>
<item> input </item>
<item> textarea </item>
<item> label </item>
<item> a </item>
<item> head </item>
<item> link </item>
<item> script </item>
</list>
<contexts>
<context attribute="Normal Text" lineEndContext="#stay" name="Normal">
<IncludeRules context="##C++" />
<IncludeRules context="DetectInplaceHTML" />
</context>
<context attribute="Normal Text" lineEndContext="#stay" name="DetectInplaceHTML">
<keyword attribute="Inplace HTML" context="#stay" String="InplaceHTML" />
</context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal" spellChecking="false" />
<itemData name="Inplace HTML" defStyleNum="dsKeyword" color="#0095ff" selColor="#ffffff" bold="1" italic="0" spellChecking="false" />
</itemDatas>
</highlighting>
</language>
The Kate C++ highlighting is not used in Qt Creator, changing/extending the Kate configuration file won't have anny affect. You could try to register a separate mime type that's not recognized as C or C++ by Qt Creator and write a Kate highlighter for that, but I don't know whether this would work.
Actually you may have few highlighters for the same language, but w/ different priority!
Take a look to syntax files: there is ISO C++ and C++ (which is a pure C++ syntax plus Qt4 addons). Also here is alternative C++ highlighters where C++ is a pure C++ syntax and C++/Qt4 is a secondary. One may use configuration settings to change priority according needs. Personally I prefer to have a pure C++ over "default" C++/Qt4.
So you may try to add your own C++/Custom syntax and boost its priority. Take a look to C++/Qt4 to get an idea how to "reuse" pure C++ syntax.
And finally, considering your example syntax, you'd better to detect your extension before fall into inherited C++ contexts.
<School>
<Child_One>
<Subject>
<name>computers</name>
<marks>55</marks>
<name>mathematics</name>
<marks>44</marks>
</Subject>
<Child_One>
<Child_Two>
<name>computers</name>
<marks>66</marks>
<name>mathematics</name>
<marks>77</marks>
</Child_Two>
</School>
Can anybody help me to find the Child_One subject name, in which he got highest marks
Thanks
First of all a few formatting things:
Your XML is not quite well formatted. It should have the same start and end tags
I believe the Subject element should look different then posted
When posting a input XML, don't use backticks, but indent the XML with 4 spaces to format it well on Stackoverflow
I used and changed the input XML to this:
<?xml version="1.0" encoding="UTF-8"?>
<School>
<Child_One>
<Subject>
<name>computers</name>
<marks>55</marks>
</Subject>
<Subject>
<name>mathematics</name>
<marks>44</marks>
</Subject>
</Child_One>
<Child_Two>
<Subject>
<name>computers</name>
<marks>66</marks>
</Subject>
<Subject>
<name>mathematics</name>
<marks>77</marks>
</Subject>
</Child_Two>
</School>
With XPath 2.0 you can use the following the find the max value:
/School/Child_One/Subject[marks = max(/School/Child_One/Subject/marks)]/name
With XPath 1.0 you can use the following (replace < with > to find minimum):
/School/Child_One/Subject[not(marks < /School/Child_One/Subject/marks)][1]/name
I have nodes that contain numbers that I would like to cast to a number and use mod. For example:
<item>
<num>1</num>
</item>
<item>
<num>2</num>
</item>
<item>
<num>3</num>
</item>
I've tried:
num mod 3 -- returns NaN
number(num) mod 3 -- returns NaN
number(string(num)) -- returns NaN
Any idea if this can be done? Even if there was a way to convert to ASCII, I would take it
Thanks in advance!
number(num) mod 3 should work. The following example files output 1 2 0 as expected.
XML
(saved as input.xml)
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="mod_test.xsl"?>
<items>
<item>
<num>1</num>
</item>
<item>
<num>2</num>
</item>
<item>
<num>3</num>
</item>
</items>
XSL
(saved as mod_text.xsl)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="//item">
<xsl:value-of select="number(num) mod 3"/>
</xsl:template>
</xsl:stylesheet>
Note: just num mod 3 in the select also works.
For reference, here is the relevant section in the documentation.
I've tried:
num mod 3 -- returns NaN
number(num) mod 3 -- returns NaN
number(string(num)) -- returns NaN
Any idea if this can be done?
As no complete XML document is provided, here are my two guesses:
The context node for the relative expressions has no num children. The solution is to assure that the context node is the correct one, or to use absolute XPath expression(s).
The not-shown XML document is in a default namespace. In this case the solution is to "register a namespace" (associate a string-prefix to the default namespace, say "x") and then replace in your expressio(s) num with x:num.
My XML:
<root>
<cars>
<makes>
<honda year="1995">
<model />
<!-- ... -->
</honda>
<honda year="2000">
<!-- ... -->
</honda>
</makes>
</cars>
</root>
I need a XPath that will get me all models for <honda> with year 1995.
so:
/root/cars/makes/honda
But how to reference an attribute?
"I need a XPath that will get me all models for <honda> with year 1995."
That would be:
/root/cars/makes/honda[#year = '1995']/model
Try /root/cars/makes/honda/#year
UPDATE: reading your question again:
/root/cars/makes/honda[#year = '1995']
Bottom line is: use # character to reference xml attributes.