First of all i would like to big thanks to everyone in this forum.
I was trying to extract one xml tag value in the below given xml string.
Input String was :-
<?xml version="1.0" encoding="UTF-8"?>
<nonpublicExecutionReportAcknowledgement xmlns="http://www.fpml.org/FpML-5/recordkeeping" fpmlVersion="5-5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.fpml.org/FpML-5/recordkeeping /../xmls/SDR/recordkeeping/fpml-main-5-5.xsd">
<header>
<inReplyTo messageIdScheme="www.abc.com/msg_id">sit:GDS:1644644:1442512894123:SRD0IFR119094084</inReplyTo>
<sentBy>DTCCEU</sentBy>
<sendTo>RRasdfjasdfasdkllkd4</sendTo>
<creationTimestamp>2015-10-14T16:47:30Z</creationTimestamp>
</header>
<originalMessage>
<nonpublicExecutionReport fpmlVersion="5-5" xmlns="http://www.fpml.org/FpML-5/recordkeeping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<header>
<messageId messageIdScheme="www.abc.com/msg_id">sit:GDS:1644644:1442512894123:SRD0IFR119094084</messageId>
<sentBy messageAddressScheme="http://www.fpml.org/coding-scheme/external/cftc/interim-compliant-identifier">RRasdfjasdfasdkllkd4</sentBy>
<sendTo>DTCCEU</sendTo>
<creationTimestamp>2015-10-14T05:54:38Z</creationTimestamp>
</header>
</nonpublicExecutionReport>
</originalMessage>
</nonpublicExecutionReportAcknowledgement>
Regex i was used to extract messageId was "(?<=>).*?.(?=\</messageId)" which is working fine. But when it comes as single xml string it was not working as expected.
Failing for the below input string.
<?xml version="1.0" encoding="UTF-8"?><nonpublicExecutionReportAcknowledgement xmlns="http://www.fpml.org/FpML-5/recordkeeping" fpmlVersion="5-5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.fpml.org/FpML-5/recordkeeping /../xmls/SDR/recordkeeping/fpml-main-5-5.xsd"><header><inReplyTo messageIdScheme="www.abc.com/msg_id">sit:GDS:1644644:1442512894123:SRD0IFR119094084</inReplyTo><sentBy>DTCCEU</sentBy><sendTo>RRasdfjasdfasdkllkd4</sendTo> <creationTimestamp>2015-10-14T16:47:30Z</creationTimestamp></header><originalMessage><nonpublicExecutionReport fpmlVersion="5-5" xmlns="http://www.fpml.org/FpML-5/recordkeeping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><header> <messageId messageIdScheme="www.abc.com/msg_id">sit:GDS:1644644:1442512894123:SRD0IFR119094084</messageId><sentBy messageAddressScheme="http://www.fpml.org/coding-scheme/external/cftc/interim-compliant-identifier">RRasdfjasdfasdkllkd4</sentBy><sendTo>DTCCEU</sendTo><creationTimestamp>2015-10-14T05:54:38Z</creationTimestamp></header></nonpublicExecutionReport> </originalMessage></nonpublicExecutionReportAcknowledgement>
Output required was :- "sit:GDS:1644644:1442512894123:SRD0IFR119094084"
the value should get extracted between
<messageId messageIdScheme="www.abc.com/msg_id"> and </messageId>
Could you please help me to build the regex string for the above problem it will be a great help.
Cheers,
KS
How about:
<inReplyTo messageIdScheme="www.abc.com/msg_id">([a-zA-Z0-9:]+)</inReplyTo>
Related
I have some pseudo-XML which I'm trying to clean up, and I'm most of the way there, but there's a problem with casing in tags.
My source looks like this...
<?xml version="1.0" encoding="UTF-8"?>
<root>
<float_node>1.0</float_node>
<text_node>Pack My Box</text_node>
<UPPER_NODE>With Five Dozen</UPPER_NODE>
<MiXeD_NoDe>SCSG1</MiXeD_NoDe>
<!-- Comment should not be changed -->
<GRANDPARENT>
<PARENT>
<Child1>Liquor Jugs</Child1>
<Child2 with-attribute="Pangrams">Jackdaws Love</Child2>
</PARENT>
<PARENT>
<Child1>My Big Sphinx</Child1>
<Child2 with-attribute="Are Great">Of Gold</Child2>
</PARENT>
</GRANDPARENT>
</root>
but what I want is this...
<?xml version="1.0" encoding="UTF-8"?>
<root>
<float_node>1.0</float_node>
<text_node>Pack My Box</text_node>
<upper_node>With Five Dozen</upper_node>
<mixed_node>SCSG1</mixed_node>
<!-- Comment should not be changed -->
<grandparent>
<parent>
<child1>Liquor Jugs</child1>
<child2 with-attribute="Pangrams">Jackdaws Love</child2>
</parent>
<parent>
<child1>My Big Sphinx</child1>
<child2 with-attribute="Are Great">Of Gold</child2>
</parent>
</grandparent>
</root>
So far I have this pattern...
<(.+)( .+)?>(.*)<\/\1>
and this substitution...
<\L$1$2>$3</\L$1>
but the output is wrong...
<?xml version="1.0" encoding="UTF-8"?>
<root>
<float_node>1.0</float_node>
<text_node>pack my box</text_node>
<upper_node>with five dozen</upper_node>
<mixed_node>scsg1</mixed_node>
<data_format>excel</data_format>
<!-- Comment should not be changed -->
<GRANDPARENT>
<PARENT>
<child1>liquor jugs</child1>
<child2 with-attribute="pangrams">jackdaws love</child2>
</PARENT>
<PARENT>
<child1>my big sphinx</child1>
<child2 with-attribute="are great">of gold</child2>
</PARENT>
</GRANDPARENT>
</root>
The \L lowercasing is being applied to the tag content and attribute as well as the tags, even though the substitution string has $2 and $3 distinct and unaltered.
Nested nodes are overlooked. Only the innermost node is altered. How should I manage the hierarchy?
Can anyone tell me where my pattern or substitution is failing?
I'm using Regex101 for help with building the regex pattern and testing... https://regex101.com/r/Oeshto/3
(I'm using Notepad++ to do the actual work since my preferred editor (VSCode) doesn't handle the required \L conversion.)
Here are the regular expressions to suit your needs. I'm sure some reg-ex wizard could optimise or make these better but they seem to get the job done. (Edited, I have removed my suggestion on the PEAR package as it was utterly nonsense when you asked for a regular-expression only)
Regular Expression.: /(<\/?[^!][^>]+)/g ( Change all tags+attributes )
Regular Expression.: /(<\w+|<\/\w+)/g ( Change only tags )
Substitution.......: \L$1
Don't forget the Global flag so it won't return after first result.
This should match all tags.
I am trying to parse the Soap response (snippet shown below) using NSXMLParser. However when I print the Element names in the didStartElemnt delegate method I only get the following elements returned.
Element's name is soap:Envelope
Element's name is soap:Body
Element's name is SearchResponse
Element's name is SearchResult
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SearchResponse xmlns="http://www.example.com/">
<SearchResult><?xml version="1.0" encoding="utf-8"?><Results xmlns="http://www.example.com/XMLSchema/SearchResult" xmlns:gms="http://www.def.ghi.uk/CM/gms" xmlns:n2=" (more here + further elements....)
Why do I not see the Results (or any subsequent) element?
Most likely it's the second <?xml . . .> directive that appears inside the <SearchResult>. That directive is only allowed at the start of an xml file.
I've been trying to add members to the wiki to no avail. Here's the link to the instructions on how to do so:
http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Connections+4.5+API+Documentation#action=openDocument&res_title=Updating_a_wiki_ic45&content=pdcontent
Basically, what I need to do is to retrieve the wiki first using this URL:
connectionsURL/wikis/basic/api/wiki/{wiki-label}/entry
And then append the information there and then send it back using a PUT request, Content-Type: application/atom+xml. The content passed should look like the one below based on the example:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<id>ignore</id>
<td:label xmlns:td="urn:ibm.com/td">Lake Champlain</td:label>
<category term="wiki" scheme="tag:ibm.com,2006:td/type" label="wiki">
</category>
<author>
<name>Bill Jones</name>
<snx:userid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">
bf9117c0-f8f2-102c-97c4-ceb7f24c5708
</snx:userid>
<email>bjones#us.example.com</email>
</author>
<td:sharedWith xmlns:td="urn:ibm.com/td">
<ca:member
xmlns:ca="http://www.ibm.com/xmlns/prod/composite-applications/v1.0"
ca:id="new_user_id"
ca:type="user"
ca:role="editor" >
</ca:member>
<ca:member
xmlns:ca="http://www.ibm.com/xmlns/prod/composite-applications/v1.0"
ca:id="anonymous-user"
ca:type="virtual"
ca:role="reader" >
</ca:member>
</td:sharedWith>
<title type="text">Long Lake</title>
<summary type="text">
modification none
</summary>
</entry>
I tried that and I always keep getting this 400 Bad Request response:
<?xml version="1.0" encoding="UTF-8" ?>
<td:error>
<td:errorCode>InvalidRequest</td:errorCode>
<td:errorMessage>Atom entry is null</td:errorMessage>
</td:error>
Try this API - https://conServer.com/wikis/basic/api/wiki/{WIKI_LABEL}/members
Then do a PUT on that resource to change the entries (I think type should be atom/xml or atom+cat/xml
Thanks
paul
I want to create a html document with a php block (just for learning purposes) from an xsl transformation of a xml document. I am using the <xsl:processing-instruction> tag.
<xsl:stylesheet version="1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:processing-instruction name="php">
<xsl:text>
setcookie("cookiename", "cookievalue");
echo "";
</xsl:text>
</xsl:processing-instruction>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="pagina">
<xsl:for-each select="paragraf">
<p>
<xsl:value-of select="."/>
</p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The result is:
<?php
setcookie("ceva", "textceva");
echo "";>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
</head>
<body>
<p>
text 1
</p>
<p>
text 2
</p>
</body>
</html>
Why is the second question mark missing? I was expecting something like <?php setcookie(...).. ?> .
It's because your pi (processing instruction) is an SGML processing instruction (HTML is SGML). Normally the default output for XSLT is XML, but whatever processor that you're using must be defaulting to HTML (or you omitted something in your XSLT example). Another clue pointing to this is that your meta elements aren't closed in the output.
Example (note the method="html"):
XSLT 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="html"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<html>
<xsl:processing-instruction name="test">pi</xsl:processing-instruction>
</html>
</xsl:template>
</xsl:stylesheet>
Output (using the XSLT as the input (or any XML file))
<html><?test pi></html>
To force an XML pi, add the xsl:output:
<xsl:output indent="yes" method="xml"/>
It's my understanding that the correct representation of a processing instruction in HTML is (or was, at the relevant point in time) to omit the question mark, and the specification for XSLT serialization says that this is what should be done by the HTML output method. Sorry, I don't have time to consult the specs just now to confirm this.
Of course, you are trying to generate stuff which is defined in the PHP specification rather than the HTML specification, and the XSLT serialization spec knows nothing of PHP.
I'm kind of new to XSLT, and I've gotten basic transformation done. Next I want to try out date manipulations, since my data will have timestamps. However, I can't seem to get any date functions to work, and it greatly frustrates me. I'm testing using Firefox 3.5, xsltproc 1.1.24, xalan 1.10, and XMLSpy 2009, and they all say that the functions I'm trying to use don't exist.
My xml looks like so:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="datetime.xsl"?>
<watcher>
<event id="1" date="2009-09-04T13:49:10-0500" type="ABCD">This is a test </event>
</watcher>
</code>
My xsl looks like so:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="event[#type='ABCD']">
<!-- Date: <xsl:value-of select="day-from-dateTime(xs:dateTime(#date))"/> -->
<!-- Date: <xsl:value-of select="day-from-dateTime(#date)"/> -->
Date: <xsl:value-of select="fn:day-from-dateTime(#date)"/>
</xsl:template>
</xsl:stylesheet>
If I make the stylesheet version 2, XMLSpy complains that it can't cast my date: XSLT 2.0 Debugging Error: Error in XPath 2.0 expression (Cast failed, invalid lexical value - xs:dateTime '2009-09-04T13:49:10-0500')
If I leave it as version 1, it complains about a different error: XSLT 1.0 Debugging Error: Error in XPath expression (Unknown function - Name and number of arguments do not match any function signature in the static context - 'day-from-dateTime')
Anytime I try to change the XSL to use a namespace, such as fn:day-from-dateTime, it refuses to work at all, with all of my parsers saying that The function number 'http://www.w3.org/2005/02/xpath-functions:day-from-dateTime' is not available and variants thereof. I know from other tests that I can use the substring() function perfectly, without needing any namespace prefix, and I believe it's in the same namespace as day-from-dateTime.
I feel like it's something incredibly easy, since all of the tutorials show functions being used, but something seems to be eluding me. Could someone show me what I'm missing?
Ouch, nasty versions thing going on here. A lot of the issues you're seeing will be because the XSLT processor you're using doesn't support XPath 2.0, which is where that day-from-dateTime function comes from.
I can get what you're trying to do to work, with a Saxon processor - Saxon-B 9.1.0.6 as my processor instead of Xalan. (Xalan appears to support XPath 1.0 only, according to the documentation)
There are a few errors in your documents:
The source document should have the timezone as 05:00, not 0500
<?xml version="1.0" encoding="UTF-8"?>
<watcher>
<event id="1" date="2009-09-04T13:49:10-05:00" type="ABCD">This is a test </event>
</watcher>
The XSLT should cast the string 2009-09-04T13:49:10-05:00 into a xs:dateTime, which is what type the argument of day-from-dateTime needs to be.
Date: <xsl:value-of select="day-from-dateTime(xs:dateTime(#date))"/>
And then it works
<?xml version="1.0" encoding="UTF-8"?>
Date: 4
Hope that helps,