<soap:envelope>
<soap:body>
<ns:Hello>11</ns:Hello>
<ns1:hai>12</ns1:hai>
</soap:body>
</soap:envelope>
from above i need to get first element name from the body root tag i.e, need to get output as a 'Hello'. Please help me, thanks in advance.
Use:
local-name(/*/*/*[1])
It is recommended to avoid using the // XPath pseudo-operator whenever the structure of the XML document is statically known, because many XPath engines evaluate it inefficiently (by traversing a complete (sub)tree).
<xsl:value-of select="local-name(//soap:body/*[1])" />
Related
I have to comment a longer XSLT and there is a fragment, I don't understand:
<xsl:template name="description" match="node/richcontent[#TYPE='NOTE']">
<xsl:element name="description"><xsl:value-of select="richcontent/html"/></xsl:element>
</xsl:template>
Can anyone help me?
Thank you!
This matches any elements called richcontent with a parent of node with an attribute whose name is TYPE and value is NOTE, and for it, inserts a description element with the value of the html element within the richcontent element.
That is the input would be like:
<node>
<richcontent type='OTHER'>...</richcontent>
<richcontent type='NOTE'><richcontent><html>[Some content...]</html></richcontent></richcontent>
</node>
And the output would be like:
<description>[Some content...]</description>
I strongly suspect the code is wrong.
(a) It seems unlikely that an element called richcontent has a child element that is also called richcontent. Not impossible, but unlikely.
(b) The use of <xsl:value-of> means that the content of the html element is stripped of all its markup. That may be what's intended, but I would want to check.
Perhaps your brief only extends to discovering what the stylesheet does, and not to assessing whether it does what it's supposed to do. But usually any detailed review of old code like this will find lots of bugs, and I would hope that you are investigating possible bugs as you go.
I'm trying to search through a site collection and find all sites that contain a particular file. TrimDuplicates is supposed to be the right way to do that. I'm calling QueryEx of the WebService object with the following XML as the string argument.
<QueryPacket xmlns='urn:Microsoft.Search.Query'>
<Query>
<TrimDuplicates includeid="false">False</TrimDuplicates>
<SupportedFormats>
<Format revision='1'>urn:Microsoft.Search.Response.Document:Document</Format>
</SupportedFormats>
<Context>
<QueryText language='en-us' type='STRING'>
"filenameForQuery"
</QueryText>
</Context>
</Query>
</QueryPacket>
The response from search.asmx is a 500 error with System.FormatException as the only piece of useful information.
It's only the TrimDuplicates element that is triggering the formatexception. Fiddling the case of the two Falses hasn't had any effect so far.
The answer is actually blindingly obvious - remove the includeid attribute and make the content of TrimDuplicates lower case.
Just wanted to point out that includeid should actually be an integer value.
More here
But as you said, it's not necessary.
I'd like to have a document\literal web-service accepting different kind of input in soap:body. Smth like
<soap:body>
<A xmlns="http://tempuri/A">
</A>
</soap:body>
as well as
<soap:body>
<B xmlns="http://tempuri/B">
</B>
</soap:body>
in the same wsdl:operation.
I tried describing and elements in inline schema block inside WSDL, but for a document\literal-style i need to specify an element for a wsdl:message part. But I don't want to wrap the request (<A> or <B>) into another container element.
Is this possible?
No it is not possible. The only way can get it working is to wrap those A and B elements with the other element for e.g. C. Then you need to specify that C element in your WSDL message.
Why this not possible because you have two different elements pointing at two different namespaces and the message only allows one element from one namespace.
For example,
In this document
< ?xml version="1.0" ? >
< SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://opcfoundation.org/webservices/XMLDA/1.0/"
xmlns:ns2="Service">
< SOAP-ENV:Body id="_0" >
if I need to select the element "Body", I need to know the prefix "SOAP-ENV". How can I get that? getting a root element and slicing the colon (:) off seems a dirty idea to me, I am sure there should be a neat way to do that. Google does not help (may be I am not searching for the right thing).
If you're doing XML processing you shouldn't need to know the prefix.
To select a node in an XML document, you need not know the prefix. You need to know the namespace, not the prefix.
If you are processing a SOAP document, then you know the namespace is http://schemas.xmlsoap.org/soap/envelope/. And that's all you need. In the XML application, you can assign your own namespace prefix.
My question is this:
If I have the following XML:
<root>
<alpha one="start">
<in>1</in>
</alpha>
</root>
and then I'll add the following path:
<root><alpha one="start"><out>2</out></alpha></root>
which results in
<root>
<alpha one="start">
<in>1</in>
</alpha>
</root>
<root>
<alpha one="start">
<out>2</out>
</alpha>
</root>
I want to be able to convert it into this:
<root>
<alpha one="start">
<in>1</in>
<out>2</out>
</alpha>
</root>
Besides implementing it myself (don't feel like reinventing the wheel today),
is there a specific way in Xerces (2.8,C++) to do it?
If so, at which point of the DOMDocuments life is the node merging done? at each insertion? at the writing of the document, explicitly on demand?
Thanks.
If you use xalan its possible to use an xpath to find the element and directly insert into the correc one.
The following code may be slow but returns all "root" elments with the attribute "one" set to "start".
selectNodes("//root[#one="start"]")
It is probably better to use the full path
selectNodes("/abc/def/.../root[#one="start"]")
or if you already have the parent element work relative
selectNodes("./root[#one="start"]")
I think to get the basic concepts xpath on wikipedia.
Isn't it just a one minute task if you know the names of the container tag where various different tags are present?
In your example, get a pointer to the alpha tag in all the XML documents and put the contents of all of them into a new document's alpha if they're not present there already.
This isn't as bad as reinventing the wheel. I'm not familiar with Xerces, but with libxml++, I would call this an easy task.