How to excract data from a xsi:type row? - xsitype

From this XML :
<Event xsi:type="steps" RealTime="2020-10-08T19:07:51.231079" UpdatedTime="2020-10-08T19:09:54.711" Rev="1" ID="9" Time="297">
<LOTS OF DATA>
<Event xsi:type="trips" RealTime="2020-10-08T19:07:51.231079" UpdatedTime="2020-10-08T19:09:54.711" Rev="1" ID="9" Time="297">
<LOTS OF DATA>
<Event xsi:type="steps" RealTime="2020-10-08T19:07:51.231079" UpdatedTime="2020-10-08T19:09:54.711" Rev="1" ID="9" Time="297">
<LOTS OF DATA>
I want to use <xsl:for-each select="Steps" to only read the data in that specific rows.
Its works if have <Event type="steps"> But not with <Event xsi:type="steps">

Related

remove duplicate entry in xml in mysql

I have duplicate entry in my xml column in my sql table see material8 key.I remove one entry.I am trying below query its removing both.Is there any way i can remove only one entry.
Update mytable set xml = replace (xml, "<Book key=\"material8\" active=\"true\" displayOrder=\"5\" />", "") where id = 9 and type_key="mykey1";
<?xml version="1.0" encoding="UTF-8"?>
<Type key="test1" publicKey="test2" >
<UIProperties>
<label locale="en_US">My book</label>
</UIProperties>
<Books>
<Book key="material1" active="true" displayOrder="0" >
<UIProperties>
<label locale="en_US">My Books</label>
</UIProperties>
</Book>
<Book key="material2" />
<Book key="material3" active="true" displayOrder="3" >
<Pages>
<Page key="material4" active="true" displayOrder="0" />
<Page key="material5" active="true" displayOrder="1" />
</Pages>
</Book>
<Book key="material6" active="true" displayOrder="4" />
<Book key="material7" active="true" displayOrder="2" />
<Book key="material8" active="true" displayOrder="5" />
<Book key="material8" active="true" displayOrder="5" />
</Books>
<Attributes>
<Attribute key="desc" />
<Attribute key="date1" />
<Attribute key="date2" />
</Attributes>
</Type>
A simple solution is to replace 2 books to 1, instead of 1 to none:
UPDATE mytable
SET xml = REPLACE(xml, "<Book key=\"material8\" active=\"true\" displayOrder=\"5\" /><Book key=\"material8\" active=\"true\" displayOrder=\"5\" />", "<Book key=\"material8\" active=\"true\" displayOrder=\"5\" />")
WHERE id = 9
AND type_key="mykey1";

How to do deep traversals with FindItem queries

I am sending the following XML query to EWS using the Office.context.mailbox.makeEwsRequestAsync method. It works as long as Traversal is set to "Shallow". I get a "The request is invalid" error when I set Traversal to "Deep".
How do I recursively search subfolders if I can't do deep searches?
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013_SP1" />
</soap:Header>
<soap:Body>
<m:FindItem Traversal="Shallow">
<m:ItemShape>
<t:BaseShape>AllProperties</t:BaseShape>
</m:ItemShape>
<m:IndexedPageItemView MaxEntriesReturned="10" Offset="0" BasePoint="Beginning" />
<m:Restriction>
<t:Contains ContainmentMode="FullString" ContainmentComparison="IgnoreCase">
<t:FieldURI FieldURI="item:Categories" />
<t:Constant Value="MyCategory" />
</t:Contains>
</m:Restriction>
<m:ParentFolderIds>
<t:DistinguishedFolderId Id="inbox" />
<t:DistinguishedFolderId Id="sentitems" />
</m:ParentFolderIds>
</m:FindItem>
</soap:Body>
</soap:Envelope>
The FindItem EWS call does not support Traversal="Deep". See FindItem.
This is because the call will search for items in the folders specified in ParentFolderIds. In order to do a recursive search, you will need to get the list of folders to include in the search by using the FindFolder EWS Operation which supports Traversal="Deep" on non public folders. See FindFolder for additional documentation.

Why is my XML file not validating, but is well-formed?

I am extremely new to XML and I have been pulling my hair out for the last 3 days over this simple file. As far as I now, EVERY element and attribute I declared is correct and I followed the textbook and re-read and re-did the assignment twice, but kept getting this one error. What am I missing, and how would I go about correcting the error and finally submitting my homework (late)?
Here is the error I keep getting, despite doing EXACTLY as the book said:
[Xerces-J 2.9.1] Validating "mdpba1.xml" against "Internal DocType Declaration" ...
Ln 33 Col 47 - Attribute "name" must be declared for element type "bands".
1 Errors
Here is my code:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!--
New Perspectives on XML
Tutorial 2
Case Problem 2
Filename: mdpba.xml
-->
<!DOCTYPE bands [
<!ENTITY celtic SYSTEM "celtic.jpg" NDATA JPG>
<!ENTITY badger SYSTEM "badger.jpg" NDATA JPG>
<!ELEMENT bands (band+)>
<!ELEMENT band (name, city, logo?, competition)>
<!ATTLIST band cid ID #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ATTLIST name grade (1 | 2 | 3 | 4 | 5 | juvenile | novice) #REQUIRED>
<!ELEMENT city (#PCDATA)>
<!ELEMENT logo EMPTY>
<!ATTLIST logo source ENTITY #REQUIRED>
<!ELEMENT competition (event, event)>
<!ELEMENT event (tune+)>
<!ATTLIST event type (MSR | Medley) #REQUIRED>
<!ELEMENT tune (#PCDATA)>
<!NOTATION JPG SYSTEM "image/jpg">
]>
<bands name="Midwest Developmental Pipe Band">
<band cid="c0001">
<name grade="juvenile">School of Celtic Bagpipes & Drumming</name>
<city>Delafield</city>
<logo source="celtic" />
<competition>
<event type="MSR">
<tune>Charlies Welcome</tune>
<tune>Mrs MacPherson of Inveran</tune>
<tune>Brown Haired Maiden</tune>
</event>
<event type="Medley">
<tune>Rowd's Hornpipe</tune>
</event>
</competition>
</band>
<band cid="c0002">
<name grade="juvenile">Badger Pipes and Drums</name>
<city>Madison</city>
<logo source="badger" />
<competition>
<event type="MSR">
<tune>Lord Alexander Kennedy</tune>
<tune>Bob of Fettercairn</tune>
<tune>Brown Haired Maiden</tune>
</event>
<event type="Medley">
<tune>Out of the Air</tune>
</event>
</competition>
</band>
<band cid="c0003">
<name grade="novice">Pardeeville School of Piping and Drumming</name>
<city>Pardeeville</city>
<competition>
<event type="MSR">
<tune>Lord Alexander Kennedy</tune>
<tune>Bob of Fettercairn</tune>
<tune>The Little Cascade</tune>
</event>
<event type="Medley">
<tune>The Radar Racketeer</tune>
</event>
</competition>
</band>
<band cid="c0004">
<name grade="3">Zoar Scottish Pipe Band</name>
<city>Zoar</city>
<competition>
<event type="MSR">
<tune>Charlies Welcome</tune>
<tune>Mrs MacPherson of Inveran</tune>
<tune>Major Manson</tune>
</event>
<event type="Medley">
<tune>Miss Lily</tune>
</event>
</competition>
</band>
<band cid="c0005">
<name grade="juvenile">Stockholm Pipe Band</name>
<city>Stockholm</city>
<competition>
<event type="MSR">
<tune>Pretty Marion</tune>
<tune>The Sheepwife</tune>
<tune>Brown Haired Maiden</tune>
</event>
<event type="Medley">
<tune>Farewell to Erin</tune>
</event>
</competition>
</band>
</bands>​
I am so inexperienced that I am unsure how to work around the issue(S) without messing something up, and any help would be GREATLY appreciated, thank you...
Your issue is because your DTD specification in the XML header doesn't specify name as a valid or expected attribute for the element <bands>
If you add the required DTD definition for this attribute to your XML, it will validate.
<!ATTLIST bands name CDATA #REQUIRED>
Here is your corrected XML:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!--
New Perspectives on XML
Tutorial 2
Case Problem 2
Filename: mdpba.xml
-->
<!DOCTYPE bands [
<!ENTITY celtic SYSTEM "celtic.jpg" NDATA JPG>
<!ENTITY badger SYSTEM "badger.jpg" NDATA JPG>
<!ELEMENT bands (band+)>
<!ATTLIST bands name CDATA #REQUIRED>
<!ELEMENT band (name, city, logo?, competition)>
<!ATTLIST band cid ID #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ATTLIST name grade (1 | 2 | 3 | 4 | 5 | juvenile | novice) #REQUIRED>
<!ELEMENT city (#PCDATA)>
<!ELEMENT logo EMPTY>
<!ATTLIST logo source ENTITY #REQUIRED>
<!ELEMENT competition (event, event)>
<!ELEMENT event (tune+)>
<!ATTLIST event type (MSR | Medley) #REQUIRED>
<!ELEMENT tune (#PCDATA)>
<!NOTATION JPG SYSTEM "image/jpg">
]>
<bands name="Midwest Developmental Pipe Band">
<band cid="c0001">
<name grade="juvenile">School of Celtic Bagpipes & Drumming</name>
<city>Delafield</city>
<logo source="celtic" />
<competition>
<event type="MSR">
<tune>Charlies Welcome</tune>
<tune>Mrs MacPherson of Inveran</tune>
<tune>Brown Haired Maiden</tune>
</event>
<event type="Medley">
<tune>Rowd's Hornpipe</tune>
</event>
</competition>
</band>
<band cid="c0002">
<name grade="juvenile">Badger Pipes and Drums</name>
<city>Madison</city>
<logo source="badger" />
<competition>
<event type="MSR">
<tune>Lord Alexander Kennedy</tune>
<tune>Bob of Fettercairn</tune>
<tune>Brown Haired Maiden</tune>
</event>
<event type="Medley">
<tune>Out of the Air</tune>
</event>
</competition>
</band>
<band cid="c0003">
<name grade="novice">Pardeeville School of Piping and Drumming</name>
<city>Pardeeville</city>
<competition>
<event type="MSR">
<tune>Lord Alexander Kennedy</tune>
<tune>Bob of Fettercairn</tune>
<tune>The Little Cascade</tune>
</event>
<event type="Medley">
<tune>The Radar Racketeer</tune>
</event>
</competition>
</band>
<band cid="c0004">
<name grade="3">Zoar Scottish Pipe Band</name>
<city>Zoar</city>
<competition>
<event type="MSR">
<tune>Charlies Welcome</tune>
<tune>Mrs MacPherson of Inveran</tune>
<tune>Major Manson</tune>
</event>
<event type="Medley">
<tune>Miss Lily</tune>
</event>
</competition>
</band>
<band cid="c0005">
<name grade="juvenile">Stockholm Pipe Band</name>
<city>Stockholm</city>
<competition>
<event type="MSR">
<tune>Pretty Marion</tune>
<tune>The Sheepwife</tune>
<tune>Brown Haired Maiden</tune>
</event>
<event type="Medley">
<tune>Farewell to Erin</tune>
</event>
</competition>
</band>
</bands>

Getting issue in making JSON request from xml request of SAP

My Requirement is to create a JSON for the below xml, and send as POST request to SAPNetweaver adapter.
SAP End point
URI: /sap/opu/odata/sap/ZPM_MOBILE_SRV/WOHeaderSet
Method: POST
Payload: 1 operation, 2 materials
XML request which contain two payload operations and material.
1. operation : WOHeaderOperation
2. materail : WOHeaderMaterial
this code basically contain two section one WOHeaderOperation and second for WOHeaderMaterial
<?xml version="1.0" encoding="UTF-8"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<atom:content type="application/xml">
<m:properties>
<d:Aufpl>1000000053</d:Aufpl>
<d:GltrpTms>1425887760</d:GltrpTms>
<d:GstrpTms>1425887760</d:GstrpTms>
<d:Auart>PM02</d:Auart>
<d:Ktext>Test for MAMBO 2</d:Ktext>
<d:Iwerk>KACT</d:Iwerk>
<d:Ingrp>KP</d:Ingrp>
<d:Gewrk>10000359</d:Gewrk>
<d:Tplnr>KAC-0P5010-PM1</d:Tplnr>
<d:Arbpl>10000359</d:Arbpl>
</m:properties>
</atom:content>
<atom:link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/WOHeaderOperation" type="application/atom+xml;type=feed" title="WOHeaderOperation">
<m:inline>
<atom:feed>
<atom:entry>
<atom:content type="application/xml">
<m:properties>
<d:Vornr>0010</d:Vornr>
<d:Ltxa1>Operation 1</d:Ltxa1>
<d:Indet>2</d:Indet>
</m:properties>
</atom:content>
</atom:entry>
</atom:feed>
</m:inline>
</atom:link>
<atom:link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/WOHeaderMaterial" type="application/atom+xml;type=feed" title="WOHeaderMaterial">
<m:inline>
<atom:feed>
<atom:entry>
<atom:content type="application/xml">
<m:properties>
<d:Vornr>0010</d:Vornr>
<d:Posnr>0010</d:Posnr>
<d:Matnr>340</d:Matnr>
<d:Werks>KACT</d:Werks>
<d:Bdmng>7.000</d:Bdmng>
<d:Meins>PCE</d:Meins>
<d:Postp>L</d:Postp>
</m:properties>
</atom:content>
</atom:entry>
<atom:entry>
<atom:content type="application/xml">
<m:properties>
<d:Vornr>0010</d:Vornr>
<d:Posnr>0020</d:Posnr>
<d:Matnr>338</d:Matnr>
<d:Werks>KACT</d:Werks>
<d:Bdmng>10.000</d:Bdmng>
<d:Meins>PCE</d:Meins>
<d:Postp>L</d:Postp>
</m:properties>
</atom:content>
</atom:entry>
<atom:entry>
<atom:content type="application/xml">
<m:properties>
<d:Vornr>0010</d:Vornr>
<d:Posnr>0030</d:Posnr>
<d:Matnr>336</d:Matnr>
<d:Werks>KACT</d:Werks>
<d:Bdmng>10.000</d:Bdmng>
<d:Meins>PCE</d:Meins>
<d:Postp>L</d:Postp>
</m:properties>
</atom:content>
</atom:entry>
</atom:feed>
</m:inline>
</atom:link>
</atom:entry>
If you want it to be JSON, request it as such:
GET /sap/opu/odata/sap/ZPM_MOBILE_SRV/WOHeaderSet?$format=json
But Gateway will accept both JSON and XML so there is really no need other than your own preference.

Fuzz JSON with Peach

I have made a small REST based webservice in Flask by reading http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask and now I wanted to fuzz the JSON using Peach framework. I know it's uses a pit file(XML) for fuzzing but my small brain is not able to make the pit file that can serve my purpose. I googled a lot for peach pit file but all goes in vain.
I need a pit file or anyone can tell how to create a pit file for fuzzing payload.
There is a nice tutorial about peach available there.
Several elements need to be defined:
a data model describing the format of the data you want to send.
a state model describing the behavior of the fuzzer.
an agent runnning and monitoring the applications under fuzzing.
a test bringing all definitions together.
Here is an example of a Peach Pit file from the tutorial.
<Peach xmlns="http://peachfuzzer.com/2012/Peach" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://peachfuzzer.com/2012/Peach ../peach.xsd">
<DataModel name="DataHTER">
<String value="HTER " mutable="false" token="true"/>
<String value=""/>
<String value="\r\n" mutable="false" token="true"/>
</DataModel>
<StateModel name="StateHTER" initialState="Initial">
<State name="Initial">
<Action type="input" ><DataModel ref="DataResponse"/></Action>
<Action type="output"><DataModel ref="DataHTER"/></Action>
<Action type="input" ><DataModel ref="DataResponse"/></Action>
</State>
</StateModel>
<DataModel name="DataResponse">
<String value=""/>
</DataModel>
<Agent name="RemoteAgent" location="tcp://127.0.0.1:9001">
<!-- Run and attach windbg to a vulnerable server. -->
<Monitor class="WindowsDebugger">
<Param name="CommandLine" value="C:\Documents and Settings\Administrator\Desktop\vulnserver\vulnserver.exe"/>
<Param name="WinDbgPath" value="C:\Program Files\Debugging Tools for Windows (x86)" />
</Monitor>
</Agent>
<Test name="TestHTER">
<Agent ref="RemoteAgent"/>
<StateModel ref="StateHTER"/>
<Publisher class="TcpClient">
<Param name="Host" value="127.0.0.1"/>
<Param name="Port" value="9999"/>
</Publisher>
<Logger class="File">
<Param name="Path" value="Logs"/>
</Logger>
</Test>
If you want to use a JSON data model, you can follow the recommendation of one of the peach architect.
1)Define a data model corresponding to the JSON.
JSON Object
{
"name":"John Smith",
"address":{
"address1":"555 Main St.",
"city":"Seattle"
}
}
Data model
<DataModel>
<String name="name" value="John Smith" />
<Block name="address">
<String name="address1" value="555 Main St." />
<String name="city" value="Seattle" />
</Block>
</DataModel>
You then have to write your own custom publisher in C#. Here is a tutorial for this.